Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angel-venchev-toptal/53bd2ffbdff1858e0794fcc3eb00be24 to your computer and use it in GitHub Desktop.
Save angel-venchev-toptal/53bd2ffbdff1858e0794fcc3eb00be24 to your computer and use it in GitHub Desktop.
putFile(url: string, file: any) {
return new Promise<FileUploadResponse>((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve ({ok: true, status: xhr.status, message: xhr.responseText});
} else {
reject({ok: false, status: xhr.status, message: xhr.responseText});
}
}
}
xhr.open('PUT', url)
xhr.setRequestHeader('Content-Type', file.type);
xhr.send(file);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment