Skip to content

Instantly share code, notes, and snippets.

@gusribeiro
Created May 22, 2020 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusribeiro/7fd233271e056d2231c51da64a501502 to your computer and use it in GitHub Desktop.
Save gusribeiro/7fd233271e056d2231c51da64a501502 to your computer and use it in GitHub Desktop.
export function imageTest(dataurl, filename) {
let arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment