Skip to content

Instantly share code, notes, and snippets.

@UnitedWithCode
Forked from virolea/upload.js
Created July 8, 2021 18:16
Show Gist options
  • Save UnitedWithCode/410e13e97cf5d6de9453c80c5dd79aa5 to your computer and use it in GitHub Desktop.
Save UnitedWithCode/410e13e97cf5d6de9453c80c5dd79aa5 to your computer and use it in GitHub Desktop.
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
axios.put('/endpoint/url', data, config)
.then(res => console.log(res))
.catch(err => console.log(err))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment