【问题标题】:cloud storage CORS云存储 CORS
【发布时间】:2019-02-15 06:45:33
【问题描述】:

我已将 Google 地球引擎中的地图导出到可公开访问的云存储桶(所有用户)。存储桶中的格式是带有 .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

我该如何解决这个问题?

【问题讨论】:

  • 在你的命令行运行:gsutil cors get gs://yourBucketName,然后告诉我打印了什么
  • 这可能是因为 OPTIONS 不在您的允许方法列表中。如果您正在传递 cookie(例如,如果您的 JavaScript 使用 withCredentials = True),则 GET 调用可能会触发预检请求。检查是否有一个 OPTIONS 预检调用,看看结果是什么。
  • cors get 显示:[ { "origin": ["*"], "responseHeader": ["Authorization", "Content-Range", "Accept", "Content-Type", " Origin", "Range"], "method": ["GET","OPTIONS"], "maxAgeSeconds": 300 } ] 我尝试运行 gsutil iam ch allUsers:objectViewer gs://youBucketName 并且没有记录任何更改。我之前已经设置了该选项。

标签: cors google-cloud-storage


【解决方案1】:

如果你想让你的所有存储桶公开可读,你需要提供IAM policies just run:

gsutil iam ch allUsers:objectViewer gs://youBucketName

更新: 您必须使用的 enpoint 是:

"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

【讨论】:

  • 做到了,没有改变。
  • 如果有帮助,这是我尝试访问平铺层的页面:soilcarboncoalition.org/html/length-of-green-season-1.html 感谢任何输入
  • 你的请求头是什么?,也请运行这个-> gsutil iam get gs://yourBucketName
  • 我想我发现了你的问题,你必须使用的端点是:"storage.googleapis.com" + bucketName + "/" ,而不是你所拥有的console.cloud.google.com/storage/browser
  • 这里是 gsutil iam get gs://mybucket 显示的内容: { "bindings": [ { "members": [ "projectEditor:maptilesfirstdraft", "projectOwner:maptilesfirstdraft" ], "role": "角色/storage.legacyBucketOwner" }, { "members": ["projectViewer:maptilesfirstdraft" ], "role": "roles/storage.legacyBucketReader" }, { "members": ["allUsers", "projectViewer:maptilesfirstdraft" ] , "角色": "roles/storage.objectViewer" } ], "etag": "CA4=" }
【解决方案2】:

终于弄明白了。在 Leaflet 中,tileLayer 应为以下形式,tms=false 且无 .png 扩展名:

var yourTileLayer = L.tileLayer('https://storage.googleapis.com/yourbucket/yourobject/{z}/{x}/{y}',{tms=false}).addToMap();

【讨论】:

    猜你喜欢
    • 2015-05-09
    • 1970-01-01
    • 2017-08-23
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 2019-11-06
    • 2018-11-17
    相关资源
    最近更新 更多