【问题标题】:Firebase Storage image upload: 400 Bad Request. Could not access bucketFirebase 存储图像上传:400 错误请求。无法访问存储桶
【发布时间】:2018-07-21 00:16:05
【问题描述】:

我设置了一个 firebase 网络项目,但无法让存储上传工作。我按照firebase documentation 中的说明进行操作。

我的存储桶权限是公开的(如果我将{bucket} 更改为实际名称没有区别)

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

我的代码是

export function upload (fileName, file) {
  let ref = firebase.storage().ref()

  ref.child(fileName).putString(file, 'data_url').then(snapshot => {
    console.log('Uploaded file')
  }).catch(e => console.error(e))

错误是

{
  "error": {
      "code": 400,
      "message": "Bad Request. Could not access bucket xx-xxx.appspot.com"
  }
}

我尝试使用存储桶权限,并尝试在谷歌云存储中添加权限,如here 所述,但没有帮助。任何想法将不胜感激!

【问题讨论】:

    标签: firebase firebase-storage http-status-code-400


    【解决方案1】:

    不要将通配符用于存储桶,而是将其写入您的规则中,例如:

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

    编辑:

    仅供公众阅读,请尝试:

     service firebase.storage {
       match /b/xx-xxx.appspot.com/o {
         match /{allPaths=**} {
           allow read;
           allow write: if request.auth != null;
         }
       }
      } 
    

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 2018-10-21
      • 2019-04-27
      • 2019-07-30
      • 2017-07-03
      • 2019-03-30
      • 2020-01-02
      • 2020-02-14
      相关资源
      最近更新 更多