11
votes

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

8

8 Answers

24
votes

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

[email protected]

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.

5
votes

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

1
votes

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

0
votes

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.

0
votes

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.

0
votes

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

0
votes

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.

0
votes

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.