Created
December 5, 2018 17:30
-
-
Save sgissinger/35ce7e49443a757af6da81555ab3cb32 to your computer and use it in GitHub Desktop.
Retrieve a file content as Base64 string
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
/** | |
* | |
* @param blob | |
*/ | |
function getBase64(blob: Blob): Promise<string> { | |
return new Promise<string>((resolve, reject) => { | |
let reader = new FileReader(); | |
reader.onloadend = function() { | |
let dataUrl = reader.result as string; | |
let base64 = dataUrl.split(',')[1]; | |
resolve(base64); | |
} | |
reader.onerror = reject; | |
reader.readAsDataURL(blob); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment