0

Hi onto my react app I need to see a document but I cannot upload it manually. I'll explain, the user if need, could upload a document and into another part of the app could see it. I want to know if there's a possibility to organize something like

<a href={userDocUploaded} target="_blank">See document</a> 

So the user onClick can see the doc opened in another tab. I do some logic but I upload the document on my store after he can see it in the review mode. So can I visualize it without charging it on localStorage or sessionStorage, should I use an external library?

Giovanni Giampaolo
  • 465
  • 1
  • 9
  • 17

2 Answers2

0

It depends on the format of the document. if it's an image you can show it by encoding it to base64 for other types of documents I'm afraid you have to have it stored at some URL.

Levon
  • 149
  • 9
  • It could be pdf or an image..so if it's pdf it's a mandatory to upload it somoewhere? – Giovanni Giampaolo May 18 '20 at 09:35
  • 1
    @GiovanniGiampaolo check out this thread, it will give you an idea how to go with showing local pdfs in the browser https://stackoverflow.com/questions/22048395/how-to-open-a-local-pdf-in-pdfjs-using-file-input – Levon May 20 '20 at 10:28
  • thanks, it can be a solution but not in the case of pngs or jpegs – Giovanni Giampaolo May 20 '20 at 12:23
  • 1
    @GiovanniGiampaolo for pngs and jpegs you can use FileReader API, check this out https://stackoverflow.com/questions/18934738/select-and-display-images-using-filereader – Levon May 20 '20 at 15:11
0

You don't need to upload it anywhere to open it, after the 'upload' (using the file chooser) you can store it in a variable and use it as you please (keep in mind that this is not always a good approach). However if you want to visualize\open it in the application, it depends on the file format and you might need to use an external library to interpret and present it

edit: add note in parenthesis

user-ic
  • 48
  • 5