是否可以使用Firebase的Firestore设置存储规则? [英] Is it possible to set storage rules using firestore of Firebase?
问题描述
因此,我正在尝试将规则设置到存储中,但是我需要访问firestore才能对其进行正确设置.
So I'm trying to set rules into storage, but I need to access to firestore to set it right.
以下是我的示例:
在我的firestore数据库中,我有一个users
集合,其中有一个名为items
的集合.路径如下所示:/users/items/{itemId}
Into my firestore database I have a users
collection which have a collection named items
. The path look like this: /users/items/{itemId}
我希望用户可以使用以下路径将文件读写到存储中:/items/{id}/file.png
,前提是该项目的{id}
已存在于firestore数据库的items
集合中.
有没有办法使用Firestore将规则正确设置到存储中?
I want that a user can read and write a file into storage with this path: /items/{id}/file.png
only if the {id}
of the item already exist into the items
collection of firestore database.
Is there a way to set correctly rules into storage using 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));
}
}
}
但这不起作用:/
感谢您的帮助!
推荐答案
一个Firebase产品的安全规则无法引用另一个Firebase产品.性能影响太大.
There is no way for security rules of one Firebase product to refer to another Firebase product. The performance implications would be too big.
如果您需要这种产品间的一致性,则可能要考虑从Cloud Functions进行写入.虽然这并不是突然允许跨产品安全性规则,但这确实意味着您要确保使用您的代码进行写操作,并且该代码在比普通用户的电话或其他用户更可靠的环境中运行PC.
If such inter-product consistency is a requirement for you, you might want to consider doing the writes from Cloud Functions. While that doesn't suddenly allow cross-product security rules, it does mean that you an ensure it is your code doing the writes and the code is running in a more reliable environment then the average user's phone or PC.
这篇关于是否可以使用Firebase的Firestore设置存储规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!