Last active
October 11, 2020 08:25
-
-
Save Jagathishrex/8710b62c198692bdd068a155d9fccf63 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
| 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