Created
November 2, 2023 19:55
-
-
Save adeleke5140/823569544759d15687f84a2cfcbc5389 to your computer and use it in GitHub Desktop.
Conversion between js formats
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 blob = b64toBlob(imageSrc.replace(/^data:image\/jpeg;base64,/, "")); | |
const file = new File([blob], "profile.jpeg", { type: "image/jpeg" }); | |
const blobURl = URL.createObjectURL(file); |
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
function convertDataUrlToFile(dataURL: string, filename: string) { | |
let arr = dataURL.split(","), | |
mime = arr[0]?.match(/:(.*?);/)![1], | |
bstr = atob(arr[arr.length - 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