我试图从firebase存储加载用户配置文件图像,但我一直在运行Cause(1 of 1):
com.google.firebase.storage.StorageException类:用户无权访问此对象。
用户身份验证:
mFirebaseAuth.signInWithEmailAndPassword(mEmailView.getText().toString(), mPasswordView.getText().toString())
这是我的firebase规则:
service firebase.storage {
match /b/brainbeats-e9839.appspot.com/o {
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
像这样滑行加载:
StorageReference storageReference = FirebaseStorage.getInstance().getReference();
StorageReference imageStorage = storageReference.child("images/" + user.getArtistProfileImage());
GlideApp.with(this)
.load(imageStorage)
.into(mArtistCoverImage);
那么你的规则授予以下访问权限:
/user/{userId}/{allPaths=**}
所以用户下的任何路径然后是用户ID位置,然后是任何东西
但是你正在访问
/images/xyzpath
现在,由于这不在/ user / variable userid /下,因此会出现异常。
为什么不在用户节点下移动图像,如:
/user/{userId}/images/yourpath
如果auth规则匹配,这应该停止给出错误。如果它是未经授权的用户访问另一个用户ID,它仍然会崩溃,所以最好将所有内容放在try catch块中