Skip to content

Instantly share code, notes, and snippets.

@nickpoulos
Created November 26, 2019 15:38
Show Gist options
  • Save nickpoulos/beda90554bd899196e7844e94f8318be to your computer and use it in GitHub Desktop.
Save nickpoulos/beda90554bd899196e7844e94f8318be to your computer and use it in GitHub Desktop.
ES2016 File Upload With Progress
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