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:
    gcloud storage buckets update gs://BUCKET_NAME --cors-file=JSON_FILE_NAME.json

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月24日 UTC.