Greetings again,
I am giving my client a signed url to upload files to cloud storage. However I am getting the following error when calling the URL :
Cross-Origin Resource Sharing error: PreflightMissingAllowOriginHeader
I am aware that I need to setup the server to receive the call using the header :
Access-Control-Allow-Origin
However I don't know where to add this header to storage since the call is being made directly to storage and not to my server...
Thanx for the help !
Solved! Go to Solution.
Hello @icepaco33!
Check out this documentation: Set up and view CORS configurations.
To setup the CORS configuration on a bucket, you can use the gcloud CLI. Use the following steps to set a CORS configuration on your bucket:
gcloud storage buckets update gs://BUCKET_NAME --cors-file=CORS_CONFIG_FILE
To view the CORS configuration for a bucket, you can use the gcloud CLI and input the command:
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"
If the above options don't work, you can contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!
Hello @icepaco33!
Check out this documentation: Set up and view CORS configurations.
To setup the CORS configuration on a bucket, you can use the gcloud CLI. Use the following steps to set a CORS configuration on your bucket:
gcloud storage buckets update gs://BUCKET_NAME --cors-file=CORS_CONFIG_FILE
To view the CORS configuration for a bucket, you can use the gcloud CLI and input the command:
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"
If the above options don't work, you can contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!
The "configuration examples" is incorrect. I got error "ERROR: 'str' object has no attribute 'items'" when running the command.
The correct format is
```
[ { "origin": ["*"], "responseHeader": ["Content-Type"], "method": ["GET", "PUT"], "maxAgeSeconds": 3600 } ]
```
I found this from the gcloud storage bucket update command documentation here
https://cloud.google.com/sdk/gcloud/reference/storage/buckets/update
I had the same problem and the format from pengxu is indeed correct. Here it is formatted with the example:
[
{
"origin": ["https://your-example-website.appspot.com"],
"method": ["GET"],
"responseHeader": ["Content-Type"],
"maxAgeSeconds": 3600
}
]