Vinicius Bortoletto
Vinicius Bortoletto

Reputation: 443

Firebase Storage "Permission denied" error

When I try to read my Firebase Storage data I'm getting the following error:

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."
  }
} 

But my rules are set to public:

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

What am I missing? Here's my code:

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;
}

Upvotes: 6

Views: 3582

Answers (2)

Before you setting for storage admin, make sure you have activate your google cloud platform. Because it's can be the first cause, if you use firebase storage and you never use google cloud platform before

Upvotes: 0

Vinicius Bortoletto
Vinicius Bortoletto

Reputation: 443

Following the steps in this post fixed my issue:

This is due to a missing permission:

[email protected]
  1. Go to https://console.cloud.google.com
  2. Select your project in the top blue bar
  3. Scroll down the left menu and select "Cloud Storage"
  4. Select all your buckets then click "ADD PRINCIPAL" on the right
  5. Add "[email protected]" and "Storage Admin" as a role
  6. Save it

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

Upvotes: 9

Related Questions