在Firestore中创建对Cloud Storage文档的引用

问题描述 投票:4回答:2

我正在使用Firebase,并尝试在Firestore文档中创建对Cloud Storage文档的引用。

在控制台中>存储,我有一个文件夹discovery,其中包含文件heart.png

在Firestore文档中,我有一个名为referencesrc字段。我尝试用以下方法填充它:

  • discovery/heart.png
  • gs://<NAME>.appspot.com/discovery/heart.png
  • <NAME>.appspot.com/discovery/heart.png

但是它不起作用。当我尝试获得像src.get().then(snap => console.log(snap.data()))这样的图像时,结果始终是undefined

参考字段是否仅设计用于数据库文档(不是存储文档)?在文档和Google上,我都找不到如何在Firestore文档中引用存储文件的信息。

有人可以帮我吗? :)非常感谢!

firebase reference google-cloud-storage google-cloud-firestore
2个回答
11
投票

Cloud Firestore的Reference字段类型只能引用Firestore数据库中的另一个文档。

如果要在Cloud Storage中引用对象/位置,则必须将其存储为兼容类型。例如,通过存储对象的下载URL或对象的路径。


0
投票

Cloud Firestore的Reference字段类型只能引用Firestore数据库中的另一个文档。如果我获得了该文档中的所有记录(包括参考字段),该怎么办? @Frank Van

© www.soinside.com 2019 - 2024. All rights reserved.