Skip to content

Instantly share code, notes, and snippets.

@taberh
Last active April 13, 2016 15:10
Show Gist options
  • Save taberh/4561156 to your computer and use it in GitHub Desktop.
Save taberh/4561156 to your computer and use it in GitHub Desktop.
Convert Data URI to Blob then can append FormData

#Covert Data URI to Blob

/**
* Convert Data URI to Blob
*/
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.splite(',')[1]);
var array = [];
var i = 0;
var l = binary.length;
for ( ; i < l; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], {type: 'image/jpeg'});
}
@apendua
Copy link

apendua commented Jul 29, 2014

In 5th line it should be `splite' of course :)

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