Search code examples
firebasegoogle-cloud-storagefirebase-storagestoragehttp-status-code-412

Firebase storage returning 412 error even after enabling storage API


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?


Solution

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