在谷歌桶上的CORS配置 [英] CORS config on google bucket

查看:213
本文介绍了在谷歌桶上的CORS配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置谷歌存储桶上的CORS配置。我指 https://cloud.google.com/storage /文档/ XML的API /把桶-CORS 。有人可以帮助我如何在python中使用这个请求。

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.

推荐答案

您可能想使用JSON API,而使用 google-cloud-storage 库。 Bucket的文档此处

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

这篇关于在谷歌桶上的CORS配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆