1

I have txt files stored inside Firebase storage. and I am able to store the download URL of each of these txt files in my firestore database. but I am not able to use the data inside the txt files stored inside firebase storage.

Problem **: I want to directly **get data from the txt file stored in the storage and display it in my reactjs web application page.

As of now, I am not able to download the txt file by putting the url in an anchor tag and I dont know how to approach this problem as i want to download the file.

And also I am not able to get data directly form the txt file stored in storage so that I can display it in the web page. . I have already looked at the documentation but the demo there only shows how to display an image from storage by assigning download url to src attribute of img tag and not other file types like txt.

I tried to put download URL inside an anchor tag, but that wouldn't download the file. and to retrieve data inside the txt file stored in storage I Couldn't find a good approach

Expected result: I want to get the data inside txt file stored in storage to display in my web page in reactjs.

Output result: not able to access the data inside the txt file in storage for viewing in the webpage.

Thank you for your time

Harry
  • 389
  • 1
  • 6
  • 18

1 Answers1

0

As mentioned above - you have 2 questions, but I'll try to answer them both.

Without code it is hard to see what you are doing, but you are saying that you have the "Download url". Are you sure? You have 2 "urls" with storage. One is the storage location starting with gs://... and the other is the download URL - which you can generate from the "storage location".

If you really have a download url -> putting it in anchor tag should enable someone to download this file. The browser will open the link and depending on the meta information it will initiate a download of the file or display it inline.

If that doesn't happen, you might be running in a cors issue. ( again no idea how you are trying to access the file. You might need to specify the urls for cors. More info here: https://cloud.google.com/storage/docs/cross-origin)

About displaying the content of the file. You need to download the file in your application. Once downloaded you can display the content of it. You can do it as suggested over here: How to read a text file from server using JavaScript?

Daniel Dimitrov
  • 1,848
  • 21
  • 35
  • I am positive that I have the download URL as I can see the data when I copy paste it into the browser address bar. there is only one download url which I save it on firestore – Harry May 29 '19 at 10:58
  • The download url, when put inside an anchor tag, takes me to a page wherein it shows only the data in that txt file. – Harry May 29 '19 at 10:59
  • so when you use the download URL directly - you can access the file in the browser? – Daniel Dimitrov May 29 '19 at 14:16
  • yes its accessible in browser when i use the url in an anchor tag. ie, it takes me to a separate webpage where only the data in the txt file is being displayed. So there is no other way to directly access the data in txt file stored in the storage of firebase? – Harry May 30 '19 at 05:37
  • that is the direct way: https://stackoverflow.com/questions/4533018/how-to-read-a-text-file-from-server-using-javascript You javascript needs to fetch the content of the file under the downloadURL. After that you can do whatever you want with it. – Daniel Dimitrov May 31 '19 at 06:00
  • Thank you but I am not able to achieve it with that – Harry May 31 '19 at 08:02