【发布时间】:2016-11-23 07:11:42
【问题描述】:
我正在使用 自定义令牌 对 Firebase 进行身份验证。我想限制只有当前用户有权写入和删除图像并授予所有人读取权限。
以下代码是我与存储相关的快速代码的一部分
let filePath = REF_STORAGE.child("/"+(FIRAuth.auth()?.currentUser?.uid)!+"/profilepic.jpeg")
let metaData = FIRStorageMetadata()
metaData.contentType = "image/jpeg"
而我目前的firebase存储规则如下图
service firebase.storage {
match /b/test-123456789.appspot.com/o {
match /{uid}/{allPaths=**} {
allow read: if request.auth != null;
allow write: if request.auth.uid == uid;
}
}
}
当我尝试上传图片时出现以下错误
用户无权访问 gs://test-123456789.appspot.com/MYAUTHUID/profilepic.jpeg。
但如果我将存储规则更改为以下存储规则,我可以上传图片,并且 profilepic 存储在 /gs://test-123456789.appspot.com/123456789/profilepic.jpeg 下
service firebase.storage {
match /b/test-123456789.appspot.com/o {
match /{allPaths=**} {
allow read: if request.auth != null;
allow write: if request.auth != null;
}
}
}
请告诉我如何解决此问题。
【问题讨论】:
-
你确定你没有过度简化你的例子吗?因为您提供的规则与 firebase.google.com/docs/storage/security/… 基本相同,因此应该可以工作。
-
@Dreamcooled。从早上开始就一直在这个问题上我还没有想出解决方案
-
你忘了回答我的问题
-
@Dreamcooled。是的,我很确定:)
标签: firebase firebase-security firebase-storage