'Firebase storage security rules 400 error issue "Permission denied. Could not access bucket xxxxx-****.appspot.com"

I keeps getting message error from firebase link saying 400 error with my firebase storage upload in my react project when trying to upload photo... everything were working fine before and uploads images successfully, but now it stop uploading of photo giving the following error, i don't know where the problem is...

The link that prompt out in inspect

POST https://firebasestorage.googleapis.com/v0/b/xxxxx-****.appspot.com/o?name=usertemp%2F0rdrGK4MRDRptAMCc3mHDveytJv1%2F0rdrGK4MRDRptAMCc3mHDveytJv1.jpg 400 ()

Here is the error from the link response

{
  "error": {
    "code": 400,
    "message": "Permission denied. Could not access bucket xxxxx-****.appspot.com. 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."
  }

Here is my security

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

I still tried changing the match to /b/xxxxx-****.appspot.com/o with still no success



Solution 1:[1]

This error happend when you are trying to upload image before creating Firebase Storage which is specific for file uploading.

Could not access bucket xxxxx-****.appspot.com. 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

Thats why you are facing the error with message Please Enable Firebase Storage for your bucket because Firebase Storage act as default location for bucket media upload.

{
  "error": {
    "code": 400,
    "message": "Permission denied. Could not access bucket xxxxx-****.appspot.com. 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."
  }

What to do?

Just Go to your project Firebase console >> Storage >> and Just Click GET STARTED enter image description here

Solution 2:[2]

I noticed that this problem was occurring on projects which didn't have the Firebase* APIs and Services enabled on the Google App Engine dashboard (see screenshot below). So I manually enabled the APIs related to firebase storage. GAE APIs & Services for a working Storage <-> Firebase app

I don't understand why some APIs and services are enabled automatically for some projects and not for others. There doesn't seem to be specific instructions on the Firebase - GCP integration steps that talk about needing to explicitly enable the firebase APIs.

This other SO thread was helpful to shed light on this apparent inconsistency

Solution 3:[3]

I have solve this by going to Storage > Rules and set read,write to true :

From this:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false; //set this to true
    }
  }
}

Change into this:

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

If it doesn't work a little troubleshoot might help; try uploading an image/file on your storage by clicking Upload File button. And try re-uploading the file from your script/code to see if it works. Then delete the sample file you uploaded. Make sure that allow read, write: is true : allow read, write: if true;

Note: This is for test development only, change the rules later on production.

Solution 4:[4]

I had the same problem. The solution consists in clicking on the Storage tag (left of firebase console) and then clicking on OK button to enable upload rules.

Solution 5:[5]

I had the same problem. The thing was, I hosted my page before initializing the storage, so when I initialized it, the bucket did not match. All I had to do was to generate another google-services.json file on firebase, download it, add it on my project file and then deploy it again. That solved my issue.

Solution 6:[6]

In case, above solutions don't work. Check whether the given StorageInstanceURL is correct or not.

Solution 7:[7]

If you are having this issue after following the myriad of solutions on this page, and IF you have recently downgraded your firebase project to the free version, you may need to ensure you are using the correct bucket.

For me, I had created a bucket in storage via the google cloud console. Later, I created a firebase project to use the storage in my unity app. I added this new bucket to my storage, so now I had a default bucket provided by firebase and the bucket I had created earlier. I uploaded files no problem via my app.

However, I then CHANGED to the free version of firebase, to avoid any unsuspected bills. The unintended consequence of this is that each firebase project gets one single bucket to use, and additional buckets are not allowed.

So, check that you are attempting to write to the default bucket instance provided by firebase and not a custom bucket you created. It will still say permission is denied and it will still tell you to make sure you have storage enabled, even though you do. The reality is that you need use the default bucket if you are on the free version of firebase.

tldr: If you are using the free version of firebase, you cannot use custom buckets and must use the default bucket created by firebase.

Solution 8:[8]

In my case the firebase-adminsdk permission was missing. I followed the accepted answer and added [email protected] to the storage admin role as follows:

Go to https://console.cloud.google.com/home/dashboard?project=your-project-name

Navigate to Storage Select your bucket then click show info panel.

Click in Add and type firebase-adminsdk-, select the autofill option

click select role > cloud storage > storage admin and save.

obs: Couldn't comment on the accepted answer because I don't have enough rep.

Solution 9:[9]

I had a similar issue: 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..

I don't why it came because I'm the user who created this project. Therefore, I have owner permissions.

This was the first image I uploaded to the bucket. After 5 minutes it worked (I changed nothing).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 kip2
Solution 3 Darwin Marcelo
Solution 4 Emile Achadde
Solution 5
Solution 6 Nevil Ghelani
Solution 7 Premier Bromanov
Solution 8 phoenixstudio
Solution 9 Nils Reichardt