Created
April 2, 2020 16:23
-
-
Save bmorrisondev/0f76b24844f2ad368c6da0851d2ea506 to your computer and use it in GitHub Desktop.
You can use this function to get a base64 encoded version of a File object for uploading to an API. Works with await, or in a promise chain.
This file contains hidden or 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
function getDataUrl(file) { | |
return new Promise((resolve, reject) => { | |
var reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = () => resolve(reader.result); | |
reader.onerror = err => reject(err); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment