Skip to content

Instantly share code, notes, and snippets.

@hartzis
Created July 23, 2015 01:16
Show Gist options
  • Save hartzis/093173bb0b82eaafa73b to your computer and use it in GitHub Desktop.
Save hartzis/093173bb0b82eaafa73b to your computer and use it in GitHub Desktop.
Upload Image File Ajax Request
uploadImage(imageFile) {
return new Promise((resolve, reject) => {
let imageFormData = new FormData();
imageFormData.append('imageFile', imageFile);
var xhr = new XMLHttpRequest();
xhr.open('post', '/upload', true);
xhr.onload = function () {
if (this.status == 200) {
resolve(this.response);
} else {
reject(this.statusText);
}
};
xhr.send(imageFormData);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment