存储的 Firebase 安全规则
Firebase Security Rules for Storage
我刚开始使用 Firebase,我可以 read/write/edit/delete 访问数据库。在我的应用程序中,如果 he/she 有权访问它,我只向用户显示数据。
我通过创建一个用户节点和另一个节点(称之为服务)并引用该用户子节点中的服务来做到这一点。
我以前从未使用过 Firebase 的安全规则,现在我想开始使用 Firebase 存储图像。
我正在学习教程,我的控制台显示,
Permission denied. Could not access bucket..
Please enable Firebase Storage for your bucket by visiting the Storage
tab in the Firebase Console and ensure that you have sufficient
permission to properly provision resources
在 SO 上搜索和搜索如何设置这些安全规则后,我不确定什么是正确的答案。一些答案建议我在我的代码中编写方法来授予权限,但文档建议我需要在 Firebase 端执行此操作。
这是例子之一
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firebase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
我无法理解人们的回答
喜欢几个月前的这个
{
"rules": {
"UsersDB": {
"$uid": {
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
}
}
}
有人可以解释当前的 Firebase(以及 iOS Swift..如果重要的话)如何做到这一点,以便用户 1 只能 read/write his/her data/photos
您需要相应的文件路径结构:
例如,当您上传文件时,像这样存储它们:
(root…) /user/uidxxx/myfile.jpg
其中 "uidxxx " 是您的身份验证数据库中定义的唯一用户 ID。
然后在 console/storage / Rules 选项卡上,您可以编写规则:
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firebase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
{userId}
是通配符,会被相应的"uidxxx"
代替
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}`enter code here`
}
}
这是 Firebase 存储的正确答案
我刚开始使用 Firebase,我可以 read/write/edit/delete 访问数据库。在我的应用程序中,如果 he/she 有权访问它,我只向用户显示数据。
我通过创建一个用户节点和另一个节点(称之为服务)并引用该用户子节点中的服务来做到这一点。
我以前从未使用过 Firebase 的安全规则,现在我想开始使用 Firebase 存储图像。
我正在学习教程,我的控制台显示,
Permission denied. Could not access bucket.. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources
在 SO 上搜索和搜索如何设置这些安全规则后,我不确定什么是正确的答案。一些答案建议我在我的代码中编写方法来授予权限,但文档建议我需要在 Firebase 端执行此操作。
这是例子之一
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firebase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
我无法理解人们的回答
喜欢几个月前的这个
{
"rules": {
"UsersDB": {
"$uid": {
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
}
}
}
有人可以解释当前的 Firebase(以及 iOS Swift..如果重要的话)如何做到这一点,以便用户 1 只能 read/write his/her data/photos
您需要相应的文件路径结构:
例如,当您上传文件时,像这样存储它们:
(root…) /user/uidxxx/myfile.jpg
其中 "uidxxx " 是您的身份验证数据库中定义的唯一用户 ID。
然后在 console/storage / Rules 选项卡上,您可以编写规则:
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firebase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
{userId}
是通配符,会被相应的"uidxxx"
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}`enter code here`
}
}
这是 Firebase 存储的正确答案