Created
August 11, 2016 20:36
-
-
Save metalvegetarianoprogresivo/90b85980ba273c90d9f90d46575d1628 to your computer and use it in GitHub Desktop.
Get blob from baseg4/image
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
function getBlob (dataURL) { | |
var BASE64_MARKER = ';base64,'; | |
if (dataURL.indexOf(BASE64_MARKER) == -1) { | |
var parts = dataURL.split(','); | |
var contentType = parts[0].split(':')[1]; | |
var raw = decodeURIComponent(parts[1]); | |
return new Blob([raw], { type: contentType }); | |
} | |
var parts = dataURL.split(BASE64_MARKER); | |
var contentType = parts[0].split(':')[1]; | |
var raw = window.atob(parts[1]); | |
var rawLength = raw.length; | |
var uInt8Array = new Uint8Array(rawLength); | |
for (var i = 0; i < rawLength; ++i) { | |
uInt8Array[i] = raw.charCodeAt(i); | |
} | |
return new Blob([uInt8Array], { type: contentType }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment