Skip to content

Instantly share code, notes, and snippets.

@mfaridzia
Forked from virolea/upload.js
Created October 7, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfaridzia/76a27aa6e61c93f8e5ced80b8a0fad3e to your computer and use it in GitHub Desktop.
Save mfaridzia/76a27aa6e61c93f8e5ced80b8a0fad3e 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