Skip to content

Instantly share code, notes, and snippets.

@virolea
Last active October 10, 2024 15:11
Show Gist options
  • Save virolea/e1af9359fe071f24de3da3500ff0f429 to your computer and use it in GitHub Desktop.
Save virolea/e1af9359fe071f24de3da3500ff0f429 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))
}
@Roey7
Copy link

Roey7 commented May 15, 2023

Nice. thanks!

@nvtienlg
Copy link

Thank you bro

@mtalha218
Copy link

Hi, but this is giving me 401 unauthorized error when i call my API, Why is that?

@MominjonVue
Copy link

Thank :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment