代码之家  ›  专栏  ›  技术社区  ›  Elinoter99

文件夹的Firebase存储权限

  •  0
  • Elinoter99  · 技术社区  · 7 年前


    bucket中有一个带有用户id的文件夹,它应该将文件上载到这个特定的文件夹中,但关键是只有该用户才能访问自己的文件夹。 我查看了文档并相应地设置了规则,但似乎遇到了权限问题

    {  "error": {    "code": 403,    "message": "Permission denied. Could not perform this operation"  }}
    

    我的规则

    service firebase.storage {
    match /b/{bucket}/o {
      match /{userId} {
        match /{allPaths=**}{
         allow read, write: if request.auth.uid == userId;
        } 
       }
     }
    }
    

    代码剪

    String userUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
    StorageReference storageRef = FirebaseStorage.getInstance().getReference();
    final StorageReference audioRef = storageRef.child("/ "+ userUid +"/"+filename());
    
     //rest of upload task here..
    

    有人能帮我找出我写的规则有什么问题吗?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Sachin Soma    7 年前

    您需要为此添加firebase身份验证。然后添加此权限。 请参阅此链接 Firebase Security Rules for Cloud Storage Reference

    得出的结论是您缺少Firebase存储桶名称。

    service firebase.storage {
    match /b/{Pass your firebase storage bucket name here}/o {
      match /{userId} {
        match /{allPaths=**}{
         allow read, write: if request.auth.uid == userId;
        } 
       }
     }
    }
    
    推荐文章