1

i am trying to use filereader to access a blob file located locally, such as c drive, then converts it back to object URL as img src. it is not working, can anyone help this?

never found anyone try to access a blob file from disk. what is the blob file type extension?

const imageOut = document.querySelector('#image-out');

    imageOut.addEventListener('load', () => {
        const reader = new FileReader();

        reader.addEventListener('load', () => {

            var f = File.createFromFileName("file:///C:/blob.blb"); 

              const arrayBuffer = reader.readAsArrayBuffer(f);

            const blob = new Blob([arrayBuffer], { type: mimeType });

            imageOut.src = URL.createObjectURL(blob);

        });
    });

empty, not show

luke
  • 61
  • 2
  • 6
  • are you trying to do that in a browser extension or what? Because, in a regular website, you cannot access a file in any place of your disk without the user selecting the file (using – Mauricio Sipmann Jul 24 '19 at 23:59

1 Answers1

0

Check how to use blob here it is clearly explained and it should be enough to get you going.

Try this: Assuming that file:///C:/blob.blb exists and you are sure, then do it like so:

    imageOut.addEventListener('load', () => {
        const reader = new FileReader();
        var f = File.createFromFileName("file:///C:/blob.blb");
        reader.addEventListener('load', (e) => {
              const arrayBuffer = reader.readAsArrayBuffer(f);

            global.blob = new Blob([arrayBuffer], { type: f.type});

        });
// notice this is outside the reader Load.

var intval = setInterval(function(){
      if(blob !== undefined){
         imageOut.src = URL.createObjectURL(blob);  
         clearInterval(intval);
      }
     }, 100);

    });

I hope it helps.

Nicholas Mberev
  • 1,563
  • 1
  • 14
  • 14
  • var f = File.createFromFileName("blob://C:/blob"); try this, but still not working. – luke Jul 25 '19 at 10:28
  • is this (blob://C:/blob) really a file PATH that is visible on your system ? read this first https://stackoverflow.com/questions/6506518/javascript-how-to-read-local-file because File.createFromFileName() requires a workable file path. – Nicholas Mberev Jul 25 '19 at 20:31