Ad

How To Display BLOB Content In JavaScript

- 1 answer

how can i display the content on a 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. How can i fix it?

Ad

Answer

I think you are missing the 'blob' packet reference and your require call does not resolve it. Install the packet with npm install blob.

You also have a typo on the new 'BLob', so make it so

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!

{ type: "application/pdf" }
Ad
source: stackoverflow.com
Ad