1

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:

Covert base64 string to JPG

Convert Base64 to image file with javascript

Sagar Mohan
  • 145
  • 1
  • 5
  • 17
  • Possible duplicate of [convert base64 to image in javascript/jquery](https://stackoverflow.com/questions/21227078/convert-base64-to-image-in-javascript-jquery) – Nils Kähler Mar 14 '19 at 14:59

0 Answers0