Skip to content

Instantly share code, notes, and snippets.

@jobsamuel
Created April 26, 2019 12:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jobsamuel/b4022d6937dad50d2d9195e62f1bcb4d to your computer and use it in GitHub Desktop.
Save jobsamuel/b4022d6937dad50d2d9195e62f1bcb4d to your computer and use it in GitHub Desktop.
How to set up CORS in your Google Cloud Storage Bucket
# Go to "Activate Google Cloud Shell" in https://console.cloud.google.com/home.
echo '[{"origin": ["*"],"responseHeader": ["Content-Type"],"method": ["GET", "HEAD"],"maxAgeSeconds": 3600}]' > cors-config.json
# If you want to restrict the access one or more specific domains, add their URL to the array:
echo '[{"origin": ["https://yourdomain.com"],"responseHeader": ["Content-Type"],"method": ["GET", "HEAD"],"maxAgeSeconds": 3600}]' > cors-config.json
# Set CORS config.
gsutil cors set cors-config.json gs://YOUR_BUCKET_NAME
# Verify if everything is OK.
gsutil cors get gs://YOUR_BUCKET_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment