ArgumentException:JSON 无法从以下位置加载 CORS 数据:(GCP)

ArgumentException: JSON CORS data could not be loaded from: (GCP)

我将 CORS 设置 写入 "cors.json" 文件,如下所示。

"cors.json":

[
    {
      "origin": ["http://localhost:8000"],
      "method": ["GET"],
      "responseHeader": ["Content-Type"],
      "maxAgeSeconds": 3600,
    }
]

然后,运行下面的命令将CORS设置设置为我的存储桶,如下所示:

gsutil cors set cors.json gs://my-bucket

但我收到以下错误:

ArgumentException: JSON CORS data could not be loaded from: [
    {
      "origin": ["http://localhost:8000"],
      "method": ["GET"],
      "responseHeader": ["Content-Type"],
      "maxAgeSeconds": 3600,
    }
]

CORS 设置是否有错误

您应该从最后一个元素中删除结尾的逗号“,”,如下所示。

"cors.json":

[
    {
      "origin": ["http://localhost:8000"],
      "method": ["GET"],
      "responseHeader": ["Content-Type"],
      "maxAgeSeconds": 3600, 
    }                   // ↑ Trailing comma
]                          

所以,这是 CORS 设置 没有尾随逗号“,” 最后一个元素如下图

"cors.json":

[
    {
      "origin": ["http://localhost:8000"],
      "method": ["GET"],
      "responseHeader": ["Content-Type"],
      "maxAgeSeconds": 3600 
    }                   // ↑ No trailing comma
]                          

然后,如果再次运行下面的命令,您可以成功设置CORS设置,没有任何错误:

gsutil cors set cors.json gs://my-bucket