【问题标题】:Firebase Storage "Permission denied" errorFirebase 存储“权限被拒绝”错误
【发布时间】:2021-11-18 23:53:09
【问题描述】:

当我尝试读取 Firebase 存储数据时,出现以下错误:

Uncaught (in promise) FirebaseError: Firebase Storage: An unknown error occurred, please check the error payload for server response. (storage/unknown)
{
  "error": {
    "code": 400,
    "message": "Permission denied. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."
  }
} 

但是我的规则是公开的:

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

我错过了什么?这是我的代码:

export const getAll = async () => {
    let list: Photo[] = [];

    const imagesFolder = ref(storage, "images");
    const photoList = await listAll(imagesFolder);

    for(let i in photoList.items) {
        let photoUrl = await getDownloadURL(photoList.items[i]);

        list.push({
            name: photoList.items[i].name,
            url: photoUrl
        });
    }

    return list;
}

【问题讨论】:

    标签: reactjs firebase


    【解决方案1】:

    按照这篇文章中的步骤解决了我的问题:

    这是由于缺少权限:

    firebase-storage@system.gserviceaccount.com
    
    1. 转到https://console.cloud.google.com
    2. 在顶部蓝色栏中选择您的项目
    3. 向下滚动左侧菜单并选择“云存储”
    4. 选择所有存储桶,然后点击右侧的“ADD PRINCIPAL”
    5. 添加“firebase-storage@system.gserviceaccount.com”和“存储 管理员”作为角色
    6. 保存

    https://newbedev.com/firebase-storage-security-rules-400-error-issue-permission-denied-could-not-access-bucket-xxxxx-appspot-com

    【讨论】:

      猜你喜欢
      • 2016-09-25
      • 2021-12-30
      • 1970-01-01
      • 2019-07-26
      • 2016-10-30
      • 2019-07-30
      • 2020-02-15
      • 2017-12-26
      相关资源
      最近更新 更多