Google Cloud StorageにCORSを設定する
Google Cloud Storage のバケットに対してブラウザからアクセスする場合のために CORS の許可設定を追加できる。
この設定はコンソールからは行えないため、gcloud CLI を使用する必要がある。
code:sh
# 設定前の状態を確認する
gcloud storage buckets describe gs://<バケット名>
# 設定ファイルを作る
echo '[
{
"origin": ["https://example.test"],
"method": "GET", "POST", "PUT", "DELETE",
"responseHeader": "Content-Type", "Access-Control-Allow-Origin",
"maxAgeSeconds": 3600
}
]' > ./cors.json
# 設定を適用する
gcloud storage buckets update gs://<バケット名> --cors-file=./cors.json
# 設定後の状態を確認する
gcloud storage buckets describe gs://<バケット名>