17

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

General Omosco
  • 606
  • 1
  • 10
  • 20

12 Answers12

39

This is due to a missing permission. You need to check whether you have

firebase-storage@system.gserviceaccount.com

as a member with a "Storage Admin" role. If you don't have one, then add it. That would fix the issue.

Here's the step on how you can check and add permissions.

  • Go to Cloud console
  • Navigate to Storage
  • Select your bucket then click show info panel.

You can also add the missing permission in the IAM & Admin if you want.

Panagiotis Panagi
  • 9,927
  • 7
  • 55
  • 103
goblin
  • 1,513
  • 13
  • 13
  • 1
    I just fixed my issue following your solution, But you need to clearly mention what permission we should add in the panel. In my case i just compared with an another healthy firebase project and found the missing permission is firebase-`storage@system.gserviceaccount.com` which need to have storage admin role – Fakhruddin Abdi May 12 '18 at 11:29
  • 6
    Any idea why this works for 6 months and suddenly causes this error? – Günter Zöchbauer May 15 '18 at 06:28
  • 2
    @GünterZöchbauer I don't know either. I think it's better to ask firebase support. I just saw this in their status dashboard https://status.firebase.google.com/incident/Storage/18003 – goblin May 16 '18 at 01:06
  • 2
    It seems they changed their rules.. but too bad without informing developers before triggering that type of errors on their project, but thanks to Goblin after i struggled my life battling this error within 2 days – General Omosco May 17 '18 at 13:51
  • 1
    I just got hit as well with this random change. jeez. luckily i found the answer in 5 mins thanks to google and this answer. Thanks to the fact that I only noticed a few days after everyone else. commiserations to all those who lost more time. – Jamona Mican May 18 '18 at 15:49
  • Just want to point out that if you're still getting error after doing the steps in the above answer. Try removing the trailing slash in your `storageBucket` key in firebase config. Bad: `storageBucket: "your-project.appspot.com/"` Good: `storageBucket: "your-project.appspot.com"` – deojeff Sep 11 '19 at 08:25
  • @goblin thank you very very much. After trying more than 6hours, it's working – Abu Saeed Nov 20 '21 at 17:14
6

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

eli
  • 8,571
  • 4
  • 30
  • 40
4

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.

Darwin Marcelo
  • 448
  • 5
  • 12
1

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

kip2
  • 6,473
  • 4
  • 55
  • 72
1

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).

Nils Reichardt
  • 3,195
  • 2
  • 18
  • 28
1

I got the same error this is how I fixed it

go to Storage in your console > Rules

then after set read,write to true :

From this

enter image description here

to

enter image description here

0

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.

Doilio Matsinhe
  • 2,131
  • 16
  • 29
0

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.

Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
0

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

Nevil Ghelani
  • 687
  • 10
  • 10
0

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.

Premier Bromanov
  • 429
  • 6
  • 15
0

In my case the firebase-adminsdk permission was missing. I followed the accepted answer and added firebase-adminsdk-xxxx@xxxxx.iam.gserviceaccount.com 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.

phoenixstudio
  • 1,776
  • 1
  • 14
  • 19
0

I have one more thing that you can check that caught me out and had a similar effect if you have custom domain.

I had just set everything up with most of the defaults, but was accessing it all for the first time from the custom domain and ran in to this problem for the storage access.

I had to go to the Cloud console APIs & Services -> Credentials screen and add my custom domain to the Authorized JavaScript origins "Web client (auto created by Google Service)" entry.

(I also had App Check enabled, which might have also been involved)