cloud storage CORS

落爺英雄遲暮 提交于 2019-12-24 12:19:41

问题


I've exported a map from Google Earth Engine into a cloud storage bucket with public access (allUsers). The format in the bucket is map tiles with .png extensions.

I've also set my CORS settings with gsutil as follows:

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

But trying to access these map tiles (with a Leaflet tileLayer) I get CORB (cross origin read blocking) errors in Chrome developer tools and nothing shows.

My response headers in Chrome DT show these:

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

How can I resolve this issue?


回答1:


If you want to make all you bucket public readable, you need to provide IAM policies just run:

gsutil iam ch allUsers:objectViewer gs://youBucketName

Update: The enpoint you must use is:

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

From documentation:

All requests to the storage.cloud.google.com URI require authentication. This applies even when allUsers have permission to access an object. If you want users to download anonymously accessible objects without authenticating, use the storage.googleapis.com URI documented in Direct API requests. For details and examples, see Accessing Public Data.

You are using directly https://console.cloud.google.com/storage and that's why you will encounter this errors

Example:

You have: https://console.cloud.google.com/storage/browser/logs1tiles/centralKansas/8/58/99

It should be: https://storage.googleapis.com/logs1tiles/centralKansas/8/58/99




回答2:


Finally got this figured out. In Leaflet, the tileLayer should be of the following form, with tms=false and no .png extension:

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


来源:https://stackoverflow.com/questions/52264456/cloud-storage-cors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!