Skip to content

Instantly share code, notes, and snippets.

@sgissinger
Created December 5, 2018 17:30
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 sgissinger/35ce7e49443a757af6da81555ab3cb32 to your computer and use it in GitHub Desktop.
Save sgissinger/35ce7e49443a757af6da81555ab3cb32 to your computer and use it in GitHub Desktop.
Retrieve a file content as Base64 string
/**
*
* @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