是否可以使用Firebase的Firestore设置存储规则?

Fro*_*ost 2 firebase google-cloud-firestore firebase-security-rules

因此,我试图将规则设置到存储中,但是我需要访问firestore才能对其进行正确设置。

这是我的示例:

在我的firestore数据库中,我有一个users集合,其中有一个名为的集合items。路径如下所示:/users/items/{itemId}

我希望用户可以使用以下路径将文件读写到存储中:/items/{id}/file.png仅当{id}该项目的已存在于itemsFirestore数据库集合中时。有没有办法使用firestore将规则正确设置到存储中?

我尝试了这个:

service firebase.storage {
  match /b/{bucket}/o {
    match /items/{item}/{allPaths=**} {
        allow read, write: if exists(/databases/{database}/documents/users/$(request.auth.uid)/items/$(item));
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用:/

谢谢你的帮助!

Fra*_*len 5

一个Firebase产品的安全规则无法引用另一个Firebase产品。性能影响太大。

如果您需要这种产品间的一致性,则可能要考虑从Cloud Functions进行写入。尽管这并不能突然允许跨产品安全规则,但这确实意味着您要确保由您的代码执行写操作,并且代码在比普通用户的电话或PC更可靠的环境中运行。