简体   繁体   English

文件阅读器读取Blob文件

[英]file reader read blob file

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. 我正在尝试使用FileReader来访问位于本地的Blob文件(例如c驱动器),然后将其转换回img src的对象URL。 it is not working, can anyone help this? 它不起作用,任何人都可以帮忙吗?

never found anyone try to access a blob file from disk. 从未发现有人尝试从磁盘访问blob文件。 what is the blob file type extension? 什么是blob文件类型扩展名?

const imageOut = document.querySelector('#image-out'); 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 空的,不显示

Check how to use blob here it is clearly explained and it should be enough to get you going. 在这里检查blob的用法它已经清楚地说明了,它应该足以使您开始工作。

Try this: Assuming that file:///C:/blob.blb exists and you are sure, then do it like so: 尝试以下操作:假设file:///C:/blob.blb存在并且您确定,那么就可以这样做:

    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. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM