使用CDN通过其下载URL访问Firebase Storage对象?

问题描述 投票:1回答:1

我在Firebase Storage中有带有下载URL的图像文件。我可以通过下载URL很好地访问它们。

我已设置Google Cloud Platform CDN指向我的Firebase存储分区。当我尝试访问存储桶中的图像时,收到拒绝访问。响应。

关于设置GCP CDN的说明指向存储桶,请使用以下格式:https://[IP_ADDRESS]/static/[REGION]/[OBJECT_NAME]

我将外部负载均衡器IP地址“ us”用于该区域,并且我已经尝试过[object_name]的一些操作。

图像文件对象的下载URL如下所示:

https://firebasestorage.googleapis.com/v0/b/xxxx.appspot.com/o/-LmBkDlSNaSqtFI8AfFX%2Ffoo%2Fbar_-LmDYUM32YieXcpjm7jR.png?alt=media&token=61E4F4A8-99BF-495E-89F0-03BB565D0D8A

所以,我尝试使用/o/之后的所有内容作为[object_name]我尝试了存储位置路径。我尝试对这两个路径中的斜线进行URL编码。

在所有情况下,我都会得到以下内容:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access denied.</Message>
    <Details>Anonymous caller does not have storage.objects.get access to buttons-dev.appspot.com/static/us/-LmBkDlSNaSqtFI8AfFH/circles/circle_-LmDYUM32YieTcpjm7jR.png.
</Details>
</Error>

[存储桶在Firebase存储中的权限设置为:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

但是,下载URL应该可以直接查看特定文件。另外,我尝试将allow: read;设置为权限,但未做任何更改。

如何通过下载URL和Google Cloud Platform CDN访问Firebase Storage对象?

firebase google-cloud-storage firebase-storage firebase-security-rules
1个回答
0
投票

过程是-

  1. 设置负载均衡器并为其启用CDN
  2. 允许公众访问要通过CDN访问的图像或整个存储桶。此链接中的说明-https://cloud.google.com/storage/docs/access-control/making-data-public
  3. 如果您在Firebase存储中有一个名为foo/bar/image.png的文件,则>

    然后只需使用http://[LOAD_BALANCER_IP_ADDRESS]/foo/bar/image.png进行访问

  4. 在您的示例中,这将起作用

http://[LOAD_BALANCER_IP_ADDRESS]/-LmBkDlSNaSqtFI8AfFX%2Ffoo%2Fbar_-LmDYUM32YieXcpjm7jR.png

基本URL取决于您在主机和路径规则中设置的内容。如果您只有一个后端设置,那么以上将按原样工作。

完整指南-https://cloud.google.com/load-balancing/docs/https/adding-backend-buckets-to-load-balancers

© www.soinside.com 2019 - 2024. All rights reserved.