简体   繁体   English

如何以编程方式将现有 GCP 存储桶集成/访问到 Firebase Swift 应用程序?

[英]How To Integrate/Access Existing GCP Storage Bucket To Firebase Swift App Programmatically?

I create buckets on GCP Storage using the Node.js library.我使用 Node.js 库在 GCP 存储上创建存储桶。 Later, I want to access these GCP Storage buckets from my Firebase iOS app.稍后,我想从我的 Firebase iOS 应用访问这些 GCP 存储桶。 However, I can't.然而,我不能。 I receive the following error when trying to access my existing GCP buckets from my iOS app:尝试从 iOS 应用访问现有 GCP 存储桶时收到以下错误:

Your bucket has not been set up properly for Firebase Storage. Please visit https://console.firebase.google.com/project/MY_PROJECT/storage/files to automatically repair this issue and then retry. If the issue lasts longer than five minutes, you may have insufficient permissions to repair the project. You can check your permissions by visiting https://console.firebase.google.com/iam-admin/iam/project?project=MY_PROJECT."

It seems like I need to go to the Firebase Storage console and manually import existing Google Cloud Storage buckets to my Firebase project (as suggested here ).好像我需要去火力地堡存储控制台和手动导入现有的谷歌云存储桶到我的火力地堡的项目(如建议在这里)。

How can I import existing GCP Storage buckets to my iOS Firebase project programmatically?如何以编程方式将现有 GCP 存储桶导入我的 iOS Firebase 项目? Or, is there a way to access existing GCP buckets and perform operations on them from my iOS app using Firebase Storage library?或者,有没有办法使用 Firebase 存储库从我的 iOS 应用访问现有的 GCP 存储桶并对其执行操作?

Note: I'm on the Blaze plan.注意:我正在使用 Blaze 计划。 firebase-storage@system.gserviceaccount.com is added to my existing GCP buckets as Storage admin, just like it is for my default Firebase Storage bucket. firebase-storage@system.gserviceaccount.com作为存储管理员添加到我现有的 GCP 存储桶中,就像我默认的 Firebase 存储存储桶一样。

Here's a screenshot from Firebase console that explains the situation.这是 Firebase 控制台的屏幕截图,解释了这种情况。 Firebase 截图

I found a doc which talks about The Firebase integration with Google Cloud Platform .我找到了一个关于Firebase 与 Google Cloud Platform 集成的文档。 It says:它说:

Cloud Storage for Firebase is tightly integrated with Google Cloud Platform. Cloud Storage for Firebase 与 Google Cloud Platform 紧密集成。 The Firebase SDKs for Cloud Storage store files directly in Google Cloud Storage buckets.适用于 Cloud Storage 的 Firebase SDK 直接将文件存储在 Google Cloud Storage 存储分区中。

Meaning that there shouldn't be problems when trying to call your GCS buckets from your app.这意味着尝试从您的应用程序调用 GCS 存储桶时应该不会出现问题。 There are a number of ways to access data stored in your Cloud Storage bucket, depending on what you want to do.有多种方法可以访问存储在 Cloud Storage 存储分区中的数据,具体取决于您要执行的操作。

For the integration itself, I found this GCS buckets and Firebase Quickstart .对于集成本身,我找到了这个GCS 存储桶和 Firebase Quickstart Yes, it's mentioned that you need to specify your bucket's location.是的,它提到您需要指定存储桶的位置。

It's mentioned that有提到

Read and write access to Storage is restricted so only authenticated users can read or write data对存储的读写访问受到限制,因此只有经过身份验证的用户才能读取或写入数据

Meaning that you have to implement an authentication process within your app.这意味着您必须在您的应用程序中实施身份验证过程。 Check also the Firebase authentication so we can also get rid of the insufficient permissions part.还要检查Firebase 身份验证,以便我们也可以摆脱insufficient permissions部分。

Hope this is helpful.希望这是有帮助的。

EDIT: Maybe I forgot to mention about the Security Rules .编辑:也许我忘了提及安全规则 After you set them, your app (and your users) will have access to your GCS buckets.设置它们后,您的应用程序(和您的用户)将有权访问您的 GCS 存储桶。 I also found a very similar case here .我也在这里找到了一个非常相似的案例。

Having encountered the same issue, I'm afraid there is no available programmatic solution right now.遇到同样的问题,恐怕目前没有可用的程序化解决方案。

Even if a bucket is created from the Admin SDK in a cloud function, it is not automatically attached to the Firebase project, which is required to apply some security rules and use it on the client side.即使在云函数中通过 Admin SDK 创建了一个存储桶,它也不会自动附加到 Firebase 项目,这是应用一些安全规则并在客户端使用它所必需的。

The attachment process itself looks like a black box.附件过程本身看起来像一个黑匣子。 There is no IAM apparent change after the bucket selection and process validation in the Firebase console.在 Firebase 控制台中进行存储桶选择和流程验证后,IAM 没有明显变化。

So, at this date, I would not recommend using custom buckets in Firebase projects for the following reasons:因此,目前我不建议在 Firebase 项目中使用自定义存储桶,原因如下:

  • It appears not possible to programmatically attach a custom bucket to a Firebase Project, the only working method being a manual addition via the web console似乎无法以编程方式将自定义存储桶附加到 Firebase 项目,唯一可行的方法是通过网络控制台手动添加
  • Regarding the very promising admin.securityRules() functions namespace, this is quite new (end of 2019) and the documentation lacks some thorough examples.关于非常有前途的admin.securityRules()函数命名空间,这是相当新的(2019 年底)并且文档缺乏一些完整的示例。

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

相关问题 无法从 iOS 应用访问 Firebase 存储默认存储桶 - Can't Access Firebase Storage Default Bucket From iOS App 如何使用Swift将Firebase集成到iOS应用中? - How to integrate Firebase in ios app using swift? Firebase:提供的存储桶与Swift中当前实例的存储存储桶不匹配 - Firebase: Provided bucket does not match the Storage bucket of the current instance in Swift iOS Swift Firebase 存储错误“未找到默认存储桶” - iOS Swift Firebase Storage error “No default Storage bucket found” Firebase Cloud Messaging与iOS App集成-Swift 4 - Firebase Cloud Messaging Integrate with iOS App - Swift 4 如何将 Linphone SDK 与现有的 Swift 项目集成? - How to integrate Linphone SDK with Existing Swift Project? IOS Swift SwiftUI Firebase “未找到默认存储桶。 您是否正确配置了 Firebase 存储?” - IOS Swift SwiftUI Firebase “No default Storage bucket found. Did you configure Firebase Storage properly?” 是否可以以编程方式将 Google 翻译集成到 iOS App 中(Swift 4)? - Is it possible to integrate Google translation in iOS App programmatically (Swift 4)? 如何将推送通知集成到现有应用程序? - How to integrate Push Notification to an already existing app? 如何将WebRTC与iOS应用程序Swift集成? - How to integrate WebRTC with ios app swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM