react-file-viewer
react-file-viewer copied to clipboard
Unable to Read blob url
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
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 :)
window.URL.createObjectURL has been deprecated by major browsers. Can't seem to find another solution for this.
Any update on this?
I got it working with plain old dataUrls! Not sure how I missed that initially.
Close issue.
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 There wasn't much to it. Just supply the BaseEncoded dataurl as the filePath. data:image/png;base64,iVBORw0KGgoAA.... for example.
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;