【问题标题】:Getting 'User does not have Permission to access this object. Code: -13021 HttpResult: 403' error. Please see details获取'用户无权访问此对象。代码:-13021 HttpResult:403' 错误。请看详情
【发布时间】:2016-06-10 18:02:36
【问题描述】:

我正在尝试从 FirebaseStorage 下载一些图像。

虽然我通过 google 对用户进行身份验证,但我仍然得到这个 错误:

E/StorageException: StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403 

尝试下载图像时。

规则如下:

service firebase.storage {
  match /b/appname-e3a12.appspot.com/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

有人回答了吗?

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-security


    【解决方案1】:

    试试

    service firebase.storage {
        match /b/appname-e3a12.appspot.com/o {
            match /{allPaths=**} {
                allow read, write: if true;
            }
        }
    }
    

    【讨论】:

    • 我应该在哪里插入这个:appname-e3a12.appspot.com?
    • 不!即使这个规则也给出了同样的错误:E/StorageException: StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403
    • 我也是初学者。我不知道了。为什么不进行身份验证?如果您不想尝试,请尝试Firebase Anonymous Login
    • 它仍然给我同样的错误我的 logCat StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403
    • 这对我有用。其他解决方案没有。
    【解决方案2】:

    您的规则看起来不错,但如果您不确定,请尝试将 allow read, write: if true; 放在规则的根目录中。

    我遇到了同样的问题,我不知道您尝试从哪个平台访问 Firebase 存储,但请检查您代码中的引用样式。存储不同于数据库。 例如在 Android 中,您应该访问这样的文件:

    StorageReference storageRef = FirebaseStorage.getInstance().reference().child("folderName/file.jpg");
    

    不是这样的:

     StorageReference storageRef = FirebaseStorage.getInstance().reference().child("folderName").child("file.jpg");
    

    您还应该阅读 David East 的这篇博文:5 tips for Firebase Storage

    【讨论】:

      【解决方案3】:

      遇到同样的问题,只允许读/写是不够的,你也应该在Firebase Console/Authentication/SIGN0IN METHOD选项卡下启用匿名帐户,然后它就可以了。

      【讨论】:

        【解决方案4】:

        您是否尝试过使用 Firebase 的默认规则?

        service firebase.storage {
            match /b/<your-firebase-storage-bucket>/o {
               match /{allPaths=**} {
                  allow read, write: if request.auth != null;
               }
            }
        }
        

        希望这会有所帮助!

        【讨论】:

          【解决方案5】:

          将数据库规则更新为:

          service firebase.storage {
                match /b/{bucket}/o {
                  match /{allPaths=**} {
                     allow read, write;
                  }
                 }
              }
          

          只需擦除这部分:if request.auth == null

          【讨论】:

          • OP 发布的数据库规则不包括 if request.auth == null - 他们会从哪里删除它?
          【解决方案6】:

          我正在添加这个答案,希望它对 Firebase 中的某人有所帮助:

          1. 转到“存储”

          2. 选择“规则”选项卡并如下编辑规则:

            service firebase.storage {
               match /b/{bucket}/o {
                 match /{allPaths=**} {
                   // Allow access by all users
                   allow read, write: if request.auth != null;
                 }
               }
             }
            

          注意:请确保您的项目名称与上述完全一致,不要将 {bucket} 替换为您的项目名称。

          编码愉快!

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-01-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-09-09
            • 1970-01-01
            相关资源
            最近更新 更多