云存储CORS

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

我已将Google地球引擎中的地图导出到具有公共访问权限的云存储桶中(allUsers)。存储桶中的格式是带有.png扩展名的地图图块。

我还用gsutil设置我的CORS设置如下:

[
    {
      "origin": ["*"],
      "responseHeader": ["Authorization", "Content-Range", "Accept", "Content-Type", "Origin", "Range"],
      "method": ["GET"],
      "maxAgeSeconds": 300
    }
]

但是尝试访问这些地图图块(使用Leaflet tileLayer)我在Chrome开发人员工具中得到CORB(跨源读取阻止)错误,并且没有任何显示。

我在Chrome DT中的回复标题显示了这些:

cache-control: no-cache, no-store, max-age=0, must-revalidate
content-type: text/html; charset=utf-8
expires: Mon, 01 Jan 1990 00:00:00 GMT

我该如何解决这个问题?

cors google-cloud-storage
2个回答
2
投票

如果你想让所有桶都公开可读,你需要提供IAM policies运行:

gsutil iam ch allUsers:objectViewer gs://youBucketName

更新:您必须使用的端点是:

"https://storage.googleapis.com/bucketName/ObjectName"

来自documentation

对storage.cloud.google.com URI的所有请求都需要身份验证。即使allUsers有权访问对象,这也适用。如果您希望用户在未经过身份验证的情况下下载匿名访问的对象,请使用Direct API请求中记录的storage.googleapis.com URI。有关详细信息和示例,请参阅访问公共数据。

你直接使用https://console.cloud.google.com/storage,这就是你会遇到这个错误的原因

例:

你有:https://console.cloud.google.com/storage/browser/logs1tiles/centralKansas/8/58/99

它应该是:https://storage.googleapis.com/logs1tiles/centralKansas/8/58/99


0
投票

终于搞清楚了。在Leaflet中,tileLayer应该是以下形式,tms = false且没有.png扩展名:

var yourTileLayer = L.tileLayer('https://storage.googleapis.com/yourbucket/yourobject/{z}/{x}/{y}',{tms=false}).addToMap();
© www.soinside.com 2019 - 2024. All rights reserved.