【发布时间】:2017-08-23 20:59:36
【问题描述】:
我正在尝试在 google 存储桶上配置 CORS。我想在每次创建新存储桶时设置 CORS 配置。我想通过云存储客户端库完成这项工作,而不是使用 XML API。有办法解决吗?
【问题讨论】:
标签: cors google-cloud-platform
我正在尝试在 google 存储桶上配置 CORS。我想在每次创建新存储桶时设置 CORS 配置。我想通过云存储客户端库完成这项工作,而不是使用 XML API。有办法解决吗?
【问题讨论】:
标签: cors google-cloud-platform
任何语言的Cloud Storage Client Libraries 似乎都没有提供直接设置 CORS 配置的能力。所以似乎唯一的选择是要么使用the XML API with the cors param,要么使用命令行using gsutil and a JSON config file,像这样:
gsutil cors set cors-json-file.json gs://[my-bucket]
cors-json-file.json 是这样的:
[
{
"origin": ["*"],
"responseHeader": ["Content-Type"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
【讨论】:
gsutil cors get gs://[bucket] 并且它显示了正确的标头,那么有时您必须等待 1 或 2 小时,让 Google Storage 传播这些更改。