user3571631
user3571631

Reputation: 841

CORS config on google bucket

I am trying to set CORS config on google bucket. I am referring https://cloud.google.com/storage/docs/xml-api/put-bucket-cors. Can someone help me with how to use this request in python.

Upvotes: 2

Views: 376

Answers (1)

Jason Hall
Jason Hall

Reputation: 20930

You probably want to use the JSON API instead, and use the google-cloud-storage library. Documentation for Bucket is here.

I haven't tried this, but something like:

from google.cloud import storage

bucket = storage.Client().get_bucket('bucket-id-here')
bucket.cors = [{
  origin: ['*', ...],
  method: ['GET', ...],
  responseHeader: ['some-resp-header', ...],
  maxAgeSeconds: 86400, # one day
}]
bucket.patch()  # Send the update

Upvotes: 3

Related Questions