Created
March 27, 2020 23:03
-
-
Save angel-venchev-toptal/53bd2ffbdff1858e0794fcc3eb00be24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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