How to use browser file system API to create an IMG

Viewed 337

On the client side, how can I use the native browser filesystem API to embed base64 image data within an IMG element?

1 Answers
function createIMGFromFS () {
  var img = document.createElement("img");
  const openFile = async () =>  {
    const [fh] = await window.showOpenFilePicker();
    var file2 = await fh.getFile();
    var name = file2.name;
    var fr = new FileReader();
    fr.readAsDataURL(file2);
    fr.onloadend = function() {
      img.src = fr.result;
    }
  }
  const file = openFile();
  return img;
}
Related