简体   繁体   English

如何在 JavaScript 中显示 BLOB 内容

[英]how to display BLOB content in JavaScript

how can i display the content on a BLOB?如何在 BLOB 上显示内容? I tried this code我试过这段代码

openBlob = fileBuffer => {
var BLob = require('blob');
const file = new BLob([fileBuffer, blob]); // You could also add the MIME type here as { 
type: "application/pdf" }
const fileURL = URL.createObjectURL(file);
console.log("fileURL" + fileURL)
window.open(fileURL, "_blank_");
 };

render() {
const archivioItems = this.state.archivio.map((archivio, i) => {
  return (
    <tr key={archivio.hash_referto}>
      <td>{archivio.tipo_esame}</td>
      <td>{archivio.data_esame}</td>
      <td>
        <Tab icon={<AssignmentIcon />}              
          className="tab"
           onClick={() => this.openBlob(archivio.uri)}></Tab>
      </td>
    </tr>
  )
})

but it says that "Module not found: Error: Can't resolve 'blob'" and when i click on the Assignment Icon it says that BLob is not defined.但它说“找不到模块:错误:无法解析'blob'”,当我点击分配图标时,它说没有定义BLob。 How can i fix it?我该如何解决?

I think you are missing the 'blob' packet reference and your require call does not resolve it.我认为您缺少“blob”数据包引用,并且您的 require 调用无法解决它。 Install the packet with npm install blob .使用npm install blob安装数据包。

You also have a typo on the new 'BLob', so make it so您在新的“BLob”上也有错字,所以就这样吧

const file = new Blob([fileBuffer, blob]); 

EDIT: Do also add the MIME type that you have left out in comments for the new Blob call!编辑:还要添加您在新 Blob 调用的注释中遗漏的 MIME 类型!

{ type: "application/pdf" }

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

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