Created
November 26, 2019 15:38
-
-
Save nickpoulos/beda90554bd899196e7844e94f8318be to your computer and use it in GitHub Desktop.
ES2016 File Upload With Progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sendFile(fileInput) { | |
let percentCompleted = 0; | |
let endpoint = '/store/uploads/here'; | |
const config = { | |
'Content-Type': 'multipart/form-data', | |
onUploadProgress: function(progressEvent) { | |
percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total); | |
console.log(percentCompleted); | |
} | |
}; | |
let data = new FormData(); | |
data.append('file', fileInput.files[0); | |
axios.post(endpoint, data, config) | |
.then(response => console.log(response)) | |
.catch(error => console.log(error)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment