PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 31, 2022

[FIXED] How do I reference an image from storage in cloud firestore? React

 July 31, 2022     file-upload, firebase, google-cloud-firestore, google-cloud-storage     No comments   

Issue

I'm so confused.

I have a form with an input field where you put in a 'title' and an upload file where you upload an 'image'. I created a doc in Cloud Firestore so these are my two fields.

Now, when I upload an image, it gets saved in Storage but I want the image to know to which title it belongs so from what I understand, I need to reference the doc in Cloud Firestore. I don't have any users so I cannot use a uid. I figured that I somehow need the 'access token' from storage, to get saved in the field 'image' in Cloud Firestore. How do I do that?

I'm a beginner so please be as specific as possible!

It's a react app.


Solution

You can simply take the string path of the image in Cloud Storage, and store that in the field of a document.

If you have a Reference to a file you just uploaded to Storage, you can use its fullPath property to save it to Firestore and locate it later. You can use the method Storage.ref(fullPath) to rebuild that Reference after you read the string back from the document.



Answered By - Doug Stevenson
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing