To convert Base64 String to JavaScript file object like as from file input form, we use fetch
.
For instance, we write
const url = "data:image/png;base6....";
const res = await fetch(url);
const blob = await res.blob();
const file = new File([blob], "File name", { type: "image/png" });
to call fetch
with the base64 URL.
Then we call res.blob
to return a promise with the blob response.
Finally, we create a file with the blob
with the File
constructor.