Last active
March 9, 2024 13:39
-
-
Save fasterv410/3f2a7a47ad4eed397b2f222dac873dad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const base64ToFile (base64Data: string, filename: string, mimeType: string): File => { | |
const binaryString = atob(base64Data) | |
const arrayBuffer = new ArrayBuffer(binaryString.length) | |
const uint8Array = new Uint8Array(arrayBuffer) | |
for (let i = 0; i < binaryString.length; i++) { | |
uint8Array[i] = binaryString.charCodeAt(i) | |
} | |
const blob = new Blob([uint8Array], { type: mimeType }) | |
return new File([blob], filename, { type: mimeType }) | |
} | |
// base64ToFile(<BASE_64>, 'banner.png', 'image/png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment