Skip to content

Instantly share code, notes, and snippets.

@virolea
Last active March 15, 2024 13:45
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))
}
@Hoodgail
Copy link

wow, this code works exactly as written by you. thanks man, nice code

@flash548
Copy link

Thank you!

@designbyadrian
Copy link

This is code and I thank.

I am not a bot.

@DawnImpulse
Copy link

simple, efficient & works... thanks a lot

@ImAARIX
Copy link

ImAARIX commented Jan 10, 2022

Thanks a lot!

@gabrielbarceloscn
Copy link

Thanks.

@mixelburg
Copy link

you lou bro :)

@premrajah
Copy link

Really helpful, thanks

@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?

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