'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".
Solution 1:[1]
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.
Solution 2:[2]
I got the same error when I tried to set the CORS settings with the trailing comma "," as shown below:
[
{
"origin": ["http://localhost:8000"],
"method": ["GET"],
"responseHeader": ["Content-Type"],
"maxAgeSeconds": 3600,
} // ? Trailing comma
]
So, I removed the trailing comma "," as shown below then I could set the CORS settings successfully without no error:
[
{
"origin": ["http://localhost:8000"],
"method": ["GET"],
"responseHeader": ["Content-Type"],
"maxAgeSeconds": 3600
} // ? No trailing comma
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lagren |
| Solution 2 |
