Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created June 3, 2016 14:02
Show Gist options
  • Save Kashkovsky/093fc4174cf52fccf81477a9bbf5ecd1 to your computer and use it in GitHub Desktop.
Save Kashkovsky/093fc4174cf52fccf81477a9bbf5ecd1 to your computer and use it in GitHub Desktop.
Convert data Uri to blob
function dataUrItoBlob(dataUri) {
var binary = atob(dataUri.split(',')[1]);
var mimeString = dataUri.split(',')[0].split(':')[1].split(';')[0];
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], { type: mimeString });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment