gpt4 book ai didi

firebase - 如何使用 Firebase 存储实现 CDN?

转载 作者:行者123 更新时间:2023-12-03 16:25:25 25 4
gpt4 key购买 nike

我目前正在开发适用于 Android 移动设备的社交媒体应用程序,但我在应用程序的成本效率方面存在问题,尤其是使用 Firebase Storage。因此,我想为 Firebase 实现一个 CDN,它可以缓存视频和图像,最好使用提供可扩展定价的 CDN 服务(Google CDN 提供此价格模型)。我一直在到处搜索如何使用 Firebase Storage 实现 google CDN,但没有找到明确的说明。我怎样才能做到这一点?

最佳答案

有几种方法可以使用 Firebase Cloud Storage 实现 CDN。
请查看文档 Firebase Cloud Storage :

Cloud Storage stores your files in a Google Cloud Storage bucket, making them accessible through both Firebase and Google Cloud. This allows you the flexibility to upload and download filesfrom mobile clients via the Firebase SDKs, and do server-sideprocessing such as image filtering or video transcoding using GoogleCloud Platform.


因此,您可以遵循文档 Setting up Cloud CDN with a backend bucket ,但请记住,只有当您通过外部 HTTP(S) 负载均衡器访问数据时,Cloud CDN 才会启动。您可以在更新后的文章 Create a Custom Domain CDN with Google 中找到示例。 @Yanan C 提到。
作为替代方案,您可以使用 Cloudflare 或其他 CDN。为此,您可以按照文章 How to Put a CDN in Front of Firebase Cloud Storage 中提供的说明进行操作。 :
  1. In Cloudflare create a new CNAME pointing your subdomain to c.storage.googleapis.com. For example: CNAME images.firerun.io c.storage.googleapis.com.
  2. In the Firebase console -> Storage, create a new bucket named the subdomain. In the example above, the bucket name would be"images.firerun.io". This is restriction where only the bucket namedthe same as the subdomain will work.
  3. Add a test file, for example: keep-calm.jpg
  4. Next, give public access to the bucket the Google Console. Note, this is different from Firebase security rules where you should setthe security rules to allow externally allow read:
  5. Go to Storage Management in the Google Console. Select your Firebase project.
  6. Click on your new bucket (e.g. images.firerun.io) and click on the tab "permissions."
  7. Click the "Add Members" button.
  8. Enter New Member as "allUsers" and Role as Cloud Storage -> Storage Object Viewer".
  9. Click "Save" and accept the warning that this is publicly accessible.

Now go to your subdomain with the file appended. For example: https://images.firerun.io/keep-calm.jpg


另外,请查看文章 Why You Should Put a CDN Like Cloudflare in Front of Firebase .

关于firebase - 如何使用 Firebase 存储实现 CDN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61409735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com