Firebase storage security rules 400 error issue “P

2019-01-12 06:54发布

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

3条回答
狗以群分
2楼-- · 2019-01-12 07:20

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.

查看更多
做自己的国王
3楼-- · 2019-01-12 07:22

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 script on firebase, paste it on my project file and then deploy it again. That solved my issue.

查看更多
时光不老,我们不散
4楼-- · 2019-01-12 07:28

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

查看更多
登录 后发表回答