Blob type open more than one file type like pdf and jpeg

2k Views Asked by At

I want to preview a file in another browser tab by clicking on a file which I uploaded before. It's working fine with {type:'application/pdf'} or {type: 'image/jpeg'} but I need both of them.

Is there a way to set more than one type for a Blob? When i get the Dokument from the Backend I don't geht the type of the file. So I can't check either a File is pdf or a jpeg.

 const fileOpen = new Blob([response], {type: 'image/jpeg' }); // this works fine!! but i need to open a pdf file as well.

 const fileUrl = URL.createObjectURL(fileOpen);
 window.open(fileUrl);
1

There are 1 best solutions below

0
lahouassa mohamed On

If response is a Fetch API Response object, you can set the type of Blob according to the type of response:

const fileOpen = new Blob([response], {type: response.data.type });

const fileUrl = URL.createObjectURL(fileOpen);
window.open(fileUrl);