Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Last active October 11, 2020 08:25
Show Gist options
  • Select an option

  • Save Jagathishrex/8710b62c198692bdd068a155d9fccf63 to your computer and use it in GitHub Desktop.

Select an option

Save Jagathishrex/8710b62c198692bdd068a155d9fccf63 to your computer and use it in GitHub Desktop.
let fileInput = document.getElementById('file_chooser');
fileInput.addEventListener('change', function(e) {
var file = this.files[0];
var fd = new FormData();
fd.append("file", file);
var request = new XMLHttpRequest();
request.open('POST', 'http:myserver.com/upload');
request.upload.onprogress = function(event) {
console.log(`Uploaded ${event.loaded} of ${event.total} bytes`);
};
request.upload.onload = function() {
console.log(`Upload finished successfully.`);
};
request.upload.onerror = function() {
console.log(`Error during the upload: ${request.status}`);
};
xhr.send(fd);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment