简体   繁体   English

Firebase 即使在启用存储后存储仍返回 412 错误 API

[英]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.我们已经使用 firebase 存储来存储我们应用程序中的图像和文件。 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 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.根据文档,我为 Firebase 服务代理创建了一个新的服务帐户,我是管理员角色作为 Cloud Storage。 It created a service account called service account name service-PROJECT_NUMBER@PROJECT_id.iam.gserviceaccount.com .它创建了一个名为服务帐户名称service-PROJECT_NUMBER@PROJECT_id.iam.gserviceaccount.com的服务帐户。 Also, I have enabled the IAM admin policies for managing services.此外,我还启用了 IAM 管理策略来管理服务。 But still but storage URL is not loading.但仍然没有加载存储 URL。

Do I need to add any more changes to storage permissions?我是否需要对存储权限添加更多更改? How can I use the existing storage bucket data with the new updates?如何将现有存储桶数据用于新更新?

I just fixed this for my self.我只是为自己解决了这个问题。

  1. Create a bucket in Cloud Storage在 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 Go 这里: 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在此处查看我的屏幕截图

As mentioned in this github .如本github中所述。

On the IAM page with the project owner role you will have an option to Grant Access.在具有项目所有者角色的IAM 页面上,您可以选择授予访问权限。 add this service account.添加此服务帐户。 service-project number@gcp-sa-firebasestorage.iam.gserviceaccount.com as a principle, Cloud Storage for Firebase Service Agent as role. service-project number@gcp-sa-firebasestorage.iam.gserviceaccount.com为原则, Cloud Storage for Firebase Service Agent为角色。

If you are having trouble adding the service account (service-@gcp-sa-firebasestorage.iam.gserviceaccount.com) to the project, it's possible that Cloud Storage for Firebase has not created it yet.如果您在将服务帐户 (service-@gcp-sa-firebasestorage.iam.gserviceaccount.com) 添加到项目时遇到问题,则可能是 Cloud Storage for Firebase 尚未创建它。

Try using the AddFirebase API to relink a bucket to your project and try again: You can refer to this尝试使用AddFirebase API将存储桶重新链接到您的项目,然后重试:您可以参考

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.在存储管理员中设置 IAM 策略后,我通过传递项目 ID 和存储桶名称尝试使用AddFirebaseAPI function 使用 postman。 But it returns a not found error for me.但它为我返回一个未找到的错误。 I tried it with both project number as well as id.我尝试了项目编号和 ID。 Both given the same error.两者都给出了相同的错误。 About the error using Postman and the URL this should be working it solved by using关于使用 Postman 和 URL 的错误这应该可以通过使用解决

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

Here is an example of the HTTP call that the playground gives you下面是 playground 给你的 HTTP 调用的例子

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.也可能需要几分钟才能反映更改。

If you open firebase-storage in console.firebase.google.com ,如果您在console.firebase.google.com中打开firebase-storage
it gives you an alert saying attach permission .它会给你一个警告说attach permission If you click on it, problem should be fixed automatically.如果单击它,问题应该会自动修复。

If it doesn't solve, then follow this Github如果还没有解决,那就按照这个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.如果您在控制台权限中找不到project number @gcp-sa-firebasestorage.iam.gserviceaccount.com firebasestorage.iam.gserviceaccount.com,请确保单击 firebase 存储中的attach permission对话框。

This is how my problem was solved.我的问题就是这样解决的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM