I'd like to convert a base64 string into a jpg file object using JavaScript.
I have tried the following (as per this thread), but it's returning me a corrupted file when I attempt to download the jpg image:
this.urltoFile(screenshot, 'file.jpg', "image/jpeg")
urltoFile(url, filename, mimeType){
return (fetch(url)
.then(function(res){return res.arrayBuffer();})
.then(function(buf){return new File([buf], filename, {type:mimeType});})
);
}
I've also tried the following threads but none of them give me a valid JavaScript File object, and if they do the resulting file is corrupt: