Peter Donovan
Peter Donovan

Reputation: 71

cloud storage CORS

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?

Upvotes: 1

Views: 450

Answers (2)

Peter Donovan
Peter Donovan

Reputation: 71

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();

Upvotes: 0

John Balvin Arias
John Balvin Arias

Reputation: 2896

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

Upvotes: 2

Related Questions