Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurrik/486405 to your computer and use it in GitHub Desktop.
Save kurrik/486405 to your computer and use it in GitHub Desktop.
var input = document.getElementById('myfileinput');
var files = input.files;
var file = files[i];
var xhr = new XMLHttpRequest();
xhr.open('post', '/path/to/destination', true);
xhr.onreadystatechange = function() {
if (this.readyState != 4) { return; }
// request finished - handle response
};
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader('X-File-Name', file.fileName);
xhr.setRequestHeader('X-File-Size', file.fileSize);
xhr.setRequestHeader('X-File-Type', file.type);
//add additional headers
xhr.send(file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment