Configure cross-origin resource sharing (CORS)

Cross Origin Resource Sharing (CORS) allows interactions between resources from different origins, something that is normally prohibited in order to prevent malicious behavior. This page explains how to configure CORS on a Cloud Storage bucket for a sample origin, the origin of the online Shaka media player.

To enable cross-origin resource sharing (CORS) on a Cloud Storage bucket, do the following:
  1. Create a JSON file that contains the following:
    [
      {
        "origin": ["https://shaka-player-demo.appspot.com/"],
        "responseHeader": ["Content-Type", "Range"],
        "method": ["GET", "HEAD"],
        "maxAgeSeconds": 3600
      }
    ]
  2. Run the following command after replacing JSON_FILE_NAME with the name of the JSON file you created in the previous step:
    gsutil cors set JSON_FILE_NAME.json gs://GCS_BUCKET_NAME