Skip to content

Instantly share code, notes, and snippets.

@marekdano
Last active November 16, 2017 16:51
Show Gist options
  • Save marekdano/6bc3d9cb667a71b100177a7f865b8e6d to your computer and use it in GitHub Desktop.
Save marekdano/6bc3d9cb667a71b100177a7f865b8e6d to your computer and use it in GitHub Desktop.
const files = event.dataTransfer ? event.dataTransfer.files : event.target.files;
const fileToUpload = files[0];
let xhr = new XMLHttpRequest(),
formData = new FormData();
formData.append("test", fileToUpload, fileToUpload.name);
xhr.onreadystatechange = () => {
if(xhr.readyState == 4) {
if(xhr.status >= 200 && xhr.status < 300)
console.log("Success", {xhr, fileToUpload})
else
console.log("Error", {xhr, fileToUpload})
}
};
xhr.open('POST', nameOfURL, true);
xhr.send(formData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment