Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Storage ArgumentException when setting CORS config

Following Google docs, when using GoogleCloud Storage console:

mysef@myproject:~$ cat cors-json-file.json 
[ 
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  } 
]

then I get the following error:

myself@myproject:~$ gsutil cors set cors-json-file.json gs://mybucket
Setting CORS on gs://mybucket/...
ArgumentException: JSON CORS data could not be loaded from: [ 
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  } 
]

same error when I remove "method", "maxAgeSeconds" or add "responseHeader".

like image 925
comte Avatar asked Jul 27 '16 16:07

comte


People also ask

How do I enable CORS in Cloud Storage?

Specify Origins that you want to allow for cross origin resource sharing with this Cloud Storage bucket. For example, https://origin1.example.com . If the origin in a browser's request matches an origin in your CORS configuration, Cloud Storage returns Access-Control-Allow-Origin to the browser.

What is Cors policy Google it and read about it?

Cross Origin Resource Sharing (CORS) allows interactions between resources from different origins, something that is normally prohibited in order to prevent malicious behavior.

What is Cors JSON?

A CORS configuration is a document that defines rules that identify the origins that you will allow to access your bucket, the operations (HTTP methods) supported for each origin, and other operation-specific information. In the S3 console, the CORS configuration must be a JSON document.


2 Answers

after so many tries, I ended up with modifing json file to:

$ cat cors-json-file.json 
[{
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
}]

and... it worked! Note that example from Google documentation is my first case (with [{ on 2 lines)

like image 87
comte Avatar answered Sep 18 '22 12:09

comte


I had the same problem and it was caused by the type of quotes used. By opening the json-file in a plain text editor and change the quote to standard ones fixed the problem.

like image 31
lagren Avatar answered Sep 22 '22 12:09

lagren