Skip to content

Instantly share code, notes, and snippets.

@exinferis
Created December 5, 2012 15:53
Show Gist options
  • Save exinferis/4216799 to your computer and use it in GitHub Desktop.
Save exinferis/4216799 to your computer and use it in GitHub Desktop.
Convert Data URI to JS blob - Javascript
dataURItoBlob = function(dataURI) {
var array, binary, i;
binary = atob(dataURI.split(",")[1]);
array = [];
i = 0;
while (i < binary.length) {
array.push(binary.charCodeAt(i));
i++;
}
return new Blob([new Uint8Array(array)], {
type: "image/jpeg"
});
};
@SuperStar518
Copy link

Very nice work!
And I'd like to add some snippet here.

...
var mimeType = dataURI.match( /(:)([a-z\/]+)(;)/ )[2] ;
...
return new Blob([new Uint8Array(array)], {
    type: mimeType
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment