【发布时间】:2018-04-26 23:48:12
【问题描述】:
目标:允许经过身份验证的用户上传个人资料照片(并将其与该用户关联)。
注意:我关注了用户文档:https://firebase.google.com/docs/storage/security/user-security
问题:我收到错误:
StorageException: StorageException has occurred.
User does not have permission to access this object.
Code: -13021 HttpResult: 403
StorageException: The server has terminated the upload session
java.io.IOException: The server has terminated the upload session
测试完成: 我首先有如下规则,并且能够允许经过身份验证的用户上传照片(但它与该用户无关): Authenticated Users
我将我的 规则 更改为以下内容以将图像与用户 ID 相关联: Associate Image to UserID
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if request.auth != null;
}
match /images {
// Only an individual user can write to "their" images
match /{userId}/{imageId} {
allow write: if request.auth.uid == userId;
}
}
}
}
使用应该将照片与用户 ID 相关联的新规则,我收到关于没有权限的存储异常错误。
如果重要的话,这是我的存储参考:
storage = FirebaseStorage.getInstance();
storageReference = storage.getReferenceFromUrl("gs://app-name.appspot.com").child("20170702_174811.jpeg"); //was PNG
还有:
public void handleChooseImage(View v) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECTED_PICTURE); //then goes to onActivityResult
}
除了文档之外,我还尝试尽可能多地观看有关该主题的 YouTube 视频,但似乎遗漏了一些内容。有人可以指出我正确的方向吗?
【问题讨论】:
标签: android firebase-realtime-database firebase-authentication firebase-storage firebase-security