react-file-viewer icon indicating copy to clipboard operation
react-file-viewer copied to clipboard

Unable to Read blob url

Open csegaurav7123 opened this issue 5 years ago • 7 comments

I am trying to add blob url as filePath. For PDF i am getting Invalid PDF Structure error, however the pdf is loading fine in browser if opened manually. and for PNG it keeps loading. Can you please help me here

csegaurav7123 avatar Mar 26 '20 08:03 csegaurav7123

Hey mate. I've had to do something similar.

I had base64 file returned from the API , so I had to fetch(base64) => parsing it to blob() and then => const fileUrl = window.URL.createObjectURL(blob); and passing that fileUrl to the <FileViewer /> component with the file type :)

AtanasChachev avatar Apr 08 '20 07:04 AtanasChachev

window.URL.createObjectURL has been deprecated by major browsers. Can't seem to find another solution for this.

foxinni avatar Aug 14 '20 15:08 foxinni

Any update on this?

foxinni avatar Sep 01 '20 08:09 foxinni

I got it working with plain old dataUrls! Not sure how I missed that initially.

Close issue.

foxinni avatar Sep 22 '20 12:09 foxinni

I got it working with plain old dataUrls! Not sure how I missed that initially.

Close issue.

@foxinni Nice! Can you share your solution please?

mmoroppa avatar Oct 27 '20 17:10 mmoroppa

@mmoroppa There wasn't much to it. Just supply the BaseEncoded dataurl as the filePath. data:image/png;base64,iVBORw0KGgoAA.... for example.

foxinni avatar Oct 29 '20 13:10 foxinni

From blob url you can get the file or from file object you can create data url:

const previewFIlePathUrl: string = "data:" + fileObj.mimeType + ";base64, " + fileObj.fileContent;

atiksarker2013 avatar May 20 '21 07:05 atiksarker2013