Created
October 19, 2019 21:33
-
-
Save aautar/e77ceaee0709b79e7fd9ac5bbddfaf5d to your computer and use it in GitHub Desktop.
Convert a data URL, with base64 encoded data, to a Blob with binary data
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
const mime = MIMEFromDataURI.getMIMEType(e.data); // using https://github.com/aautar/mime-from-data-uri | |
const dataB64 = e.data.split(',')[1]; | |
const imageDataStr = window.atob(dataB64); | |
const imageDataBinaryArr = new Uint8Array(new ArrayBuffer(imageDataStr.length)); | |
for (let i=0; i<imageDataStr.length; i++) { | |
imageDataBinaryArr[i] = imageDataStr.charCodeAt(i); | |
} | |
const blob = new Blob([imageDataBinaryArr], {type: mime}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment