12
votes

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 !

1
Answer on one of your questions below. If you're having trouble reading/writing a Cloud Storage URL to Firestore with that knowledge, edit your question to include the minimal code that reproduces the problem.Frank van Puffelen

1 Answers

23
votes

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.