Firebase storage returning 412 error even after enabling storage API
Asked Answered
P

4

5

We have already used firebase storage for storing the images and files in our application. Recently our files seem to bee not loading in the application and once cross-checking I found the following error.

{
  "error": {
    "code": 412,
    "message": "A required service account is missing necessary permissions. Please resolve by visiting the Storage page of the Firebase Console and re-linking your Firebase bucket or see this FAQ for more info: https://firebase.google.com/support/faq#storage-accounts"
  }
}

After further investigation, I found a solution in the below-related FAQ. https://firebase.google.com/support/faq/index#storage-accounts

As per the documentation, I have created a new service account with the I am admin role as Cloud Storage for Firebase Service Agent. It created a service account called service account name service-PROJECT_NUMBER@PROJECT_id.iam.gserviceaccount.com. Also, I have enabled the IAM admin policies for managing services. But still but storage URL is not loading.

Do I need to add any more changes to storage permissions? How can I use the existing storage bucket data with the new updates?

Pindaric answered 26/9, 2022 at 10:1 Comment(1)
please add service-project [email protected] as a principle and Cloud Storage for Firebase Service Agent as role as mentioned in this githubIncised
P
0

I fixed the issue with the following steps. After setting the IAM policies in storage admin I tried with AddFirebaseAPI function using postman by passing the project id and storage bucket name. But it returns a not found error for me. I tried it with both project number as well as id. Both given the same error. About the error using Postman and the URL this should be working it solved by using

https://firebasestorage.googleapis.com/v1beta/projects/<projectid>/buckets/<bucketname>:addFirebase

Here is an example of the HTTP call that the playground gives you

POST 
https://firebasestorage.googleapis.com/v1beta/projects/<projectid>/buckets/<bucketname>:addFirebase?key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

It will returns your bucket instance. Also it may takes a few mins to reflect the changes.

Pindaric answered 29/9, 2022 at 22:23 Comment(0)
P
5

I just fixed this for my self.

  1. Create a bucket in Cloud Storage
  2. Get your projectname and bucket name
  3. Go here: https://firebase.google.com/docs/reference/rest/storage/rest/v1beta/projects.buckets/addFirebase
  4. Press Try IT
  5. Fill in your projectname en bucket name. Press Execute é voila!

See my screenshot here

Plata answered 26/9, 2022 at 13:44 Comment(1)
Actually, I don't want to create a new bucket for the fire storage because there are loads of production data was there in my application. I need to relink the existing bucket with new api.Pindaric
I
2

As mentioned in this github.

On the IAM page with the project owner role you will have an option to Grant Access. add this service account. service-project [email protected] as a principle, Cloud Storage for Firebase Service Agent as role.

If you are having trouble adding the service account ([email protected]) to the project, it's possible that Cloud Storage for Firebase has not created it yet.

Try using the AddFirebase API to relink a bucket to your project and try again: You can refer to this

Incised answered 27/9, 2022 at 6:3 Comment(1)
I already added this. But it didn't work. Then I tried the AddFirebaseAPI to relink existing. But it returns a not found error. Later the same API works for me. Thanks !!!Pindaric
G
1

If you open firebase-storage in console.firebase.google.com,
it gives you an alert saying attach permission. If you click on it, problem should be fixed automatically.

If it doesn't solve, then follow this Github

If you don't find project number @gcp-sa-firebasestorage.iam.gserviceaccount.com in console permission, then make sure you click on attach permission dialog in firebase storage.

This is how my problem was solved.

Gondola answered 2/10, 2022 at 9:36 Comment(0)
P
0

I fixed the issue with the following steps. After setting the IAM policies in storage admin I tried with AddFirebaseAPI function using postman by passing the project id and storage bucket name. But it returns a not found error for me. I tried it with both project number as well as id. Both given the same error. About the error using Postman and the URL this should be working it solved by using

https://firebasestorage.googleapis.com/v1beta/projects/<projectid>/buckets/<bucketname>:addFirebase

Here is an example of the HTTP call that the playground gives you

POST 
https://firebasestorage.googleapis.com/v1beta/projects/<projectid>/buckets/<bucketname>:addFirebase?key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

It will returns your bucket instance. Also it may takes a few mins to reflect the changes.

Pindaric answered 29/9, 2022 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.