Cloud/GCP

GCS 버킷 CORS 적용

제이널 2023. 3. 20. 21:47

1. JSON 파일 준비

example.json

[{
   "origin": ["*"],
   "responseHeader": [
      "Content-Type",
      "Access-Control-Allow-Origin",
      "x-goog-resumable"
   ],
   method: ["PUT", "GET", "HEAD", "DELETE", "POST", "OPTIONS"],
   "maxAgeSeconds": 3600
}]

위 예시는 모든 출처 도메인을 허용하고, 모든 HTTP 메소드를 허용하는 CORS 설정입니다.

 

2. GCP 콘솔에 명령어 입력

gcloud storage buckets update gs://BUCKET_NAME --cors-file=example.json

 

3. 설정 확인

gcloud storage buckets describe gs://BUCKET_NAME

 

4. 설정 삭제

gcloud storage buckets update gs://BUCKET_NAME --clear-cors

참고

https://cloud.google.com/storage/docs/using-cors?hl=ko#command-line 

https://cloud.google.com/storage/docs/cors-configurations?hl=ko