Skip to content

Instantly share code, notes, and snippets.

@jcblw
Created December 7, 2016 04:07
Show Gist options
  • Save jcblw/32babcdee2136fd520e72c066ffabaa9 to your computer and use it in GitHub Desktop.
Save jcblw/32babcdee2136fd520e72c066ffabaa9 to your computer and use it in GitHub Desktop.
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