Skip to content

Instantly share code, notes, and snippets.

@metalvegetarianoprogresivo
Created August 11, 2016 20:36
Show Gist options
  • Save metalvegetarianoprogresivo/90b85980ba273c90d9f90d46575d1628 to your computer and use it in GitHub Desktop.
Save metalvegetarianoprogresivo/90b85980ba273c90d9f90d46575d1628 to your computer and use it in GitHub Desktop.
Get blob from baseg4/image
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