I am using Firebase and I try to create a reference to a Cloud Storage document in a Firestore document.
In my Console > Storage, I have a folder discovery
who contain a file heart.png
.
In my Firestore document, I have a reference
field named src
. I have tried to fill it with:
discovery/heart.png
gs://<NAME>.appspot.com/discovery/heart.png
<NAME>.appspot.com/discovery/heart.png
but it is doesn't work..
When I try to get the image like this src.get().then(snap => console.log(snap.data()))
the result is always undefined
.
Does the reference fields are only designed to the databases documents (not Storage ones) ? I can't find how to reference a Storage file in a Firestore document neither on the documentation nor on Google.
Could someone help me please ? :) Thanks a lot !
References are lightweight, so you can create as many as you need, and they are also reusable for multiple operations. To create a reference, get an instance of the Storage service using getStorage() then call ref() with the service as an argument. This reference points to the root of your Cloud Storage bucket.
firestore. DocumentReference. < T > A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist.
Image URL is obtained by uploading an image to firebase bucket and then that can return back a URL that URL is a permanent URL which can be open anywhere. Then a user can use this URL for any purpose in its application.
The Reference
field type of Cloud Firestore can only refer to another document in the Firestore database.
If you want to refer to an object/location in Cloud Storage, you'll have to store that as a compatible type. For example by storing the download URL of the object, or the path to the object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With