Skip to content Skip to sidebar Skip to footer

How To Use Browser File System API To Create An IMG

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

Solution 1:

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;
}

Post a Comment for "How To Use Browser File System API To Create An IMG"