Skip to content

Instantly share code, notes, and snippets.

@devmariodiaz
Last active October 31, 2022 16:44
Show Gist options
  • Save devmariodiaz/9d7baffbb47973a14777043e99220357 to your computer and use it in GitHub Desktop.
Save devmariodiaz/9d7baffbb47973a14777043e99220357 to your computer and use it in GitHub Desktop.
const base64 = '...';
const imageName = 'name.png';
const imageBlob = this.dataURItoBlob(base64);
const imageFile = new File([imageBlob], imageName, { type: 'image/png' });
dataURItoBlob(dataURI) {
const byteString = window.atob(dataURI);
const arrayBuffer = new ArrayBuffer(byteString.length);
const int8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i++) {
int8Array[i] = byteString.charCodeAt(i);
}
const blob = new Blob([int8Array], { type: 'image/png' });
return blob;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment