Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active February 24, 2023 06:05
Show Gist options
  • Save Klerith/e22c546d433226c47cedb4307846bb64 to your computer and use it in GitHub Desktop.
Save Klerith/e22c546d433226c47cedb4307846bb64 to your computer and use it in GitHub Desktop.
JavaScript: Base64 image to Blob
// String base 64 to blob
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var blob = new Blob([ab], {type: mimeString});
return blob;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment