Last active
May 11, 2020 22:56
-
-
Save Piterden/e1828597c682362c1f51c6876d57ae0a to your computer and use it in GitHub Desktop.
This file contains 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 send = (file) => { | |
const xhr = new XMLHttpRequest(); | |
const formData = new FormData(); | |
formData.append("avatar", file); | |
xhr.open("POST", "/", true); | |
xhr.upload.onprogress = function(event) { | |
if (event.lengthComputable) { | |
const percent = (event.loaded / event.total) * 100; | |
document.getElementById("output").innerText = percent + "%"; | |
} | |
}; | |
xhr.send(formData); | |
}; | |
const click = () => { | |
const file = document.getElementById("file").files[0]; | |
send(file); | |
}; | |
document.getElementById("btn").addEventListener("click", click); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment