Skip to content

Instantly share code, notes, and snippets.

@amici-fos
Created September 24, 2016 19:33
Show Gist options
  • Save amici-fos/72414570ff89e0e3827993bf022972c7 to your computer and use it in GitHub Desktop.
Save amici-fos/72414570ff89e0e3827993bf022972c7 to your computer and use it in GitHub Desktop.
function UploadFile(file) {
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function(e) {
var pc = parseInt((e.loaded / e.total * 100));
document.getElementById("progressbar").value= pc;
document.getElementById("progressbarstatus").innerHTML= pc +"% upload done";
}, false);
xhr.onreadystatechange = function(e) {
if (xhr.readyState ==200) {
console.log(e);
}
};
var formData = new FormData();
formData.append('file', file);
xhr.open("POST",uploadurl, true);
//xhr.setRequestHeader("X_FILENAME", file.name);
xhr.send(formData);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment