Skip to content

Instantly share code, notes, and snippets.

@Samnan
Forked from ambethia/html5-upload-progress.js
Created June 27, 2011 11:02
Show Gist options
  • Save Samnan/1048677 to your computer and use it in GitHub Desktop.
Save Samnan/1048677 to your computer and use it in GitHub Desktop.
HTML5 Upload Progress
var xhr = new XMLHttpRequest();
xhr.upload['onprogress'] = function(xhrpe) {
console.log(xhrpe);
};
var file = document.getElementById('source').files[0];
xhr.open("POST", this.action, true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", file.fileName);
xhr.setRequestHeader("X-File-Size", file.fileSize);
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.send(file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment