Reputation: 841
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
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