Created
December 7, 2016 04:07
-
-
Save jcblw/32babcdee2136fd520e72c066ffabaa9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formData = new FormData(); | |
const URL = '/path-to-something'; | |
var req = new XMLHttpRequest(); | |
formData.append('file', /* a file */); | |
req.upload.addEventListener('progress', (e) => { | |
if (!e.lengthComputable) return; | |
console.log(`${(Math.round((e.loaded/e.total)*100))}% done`); | |
}); | |
req.onload = () => console.log('all done'); | |
req.onerror = () => console.log('an error happened'); | |
req.open('POST', URL, true); | |
req.send(formData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment