我将使用gsutil设置我的存储桶的CORS,我相信它应该可以工作,但我还没有解决“请求的资源上不存在'Access-Control-Allow-Origin'头”的错误。
这是我的cors json:
以下是请求失败时的临时标头内容:
这是GCS飞行前请求的响应结果:
尽管看起来很愚蠢,但这似乎是一个大小写敏感问题。
这是我的cors json:
[
{
"origin": [
"*"
],
"responseHeader": [
"Content-Type",
"Content-MD5"
],
"method": [
"PUT",
"POST",
"GET",
"HEAD",
"DELETE",
"OPTIONS"
],
"maxAgeSeconds": 3600
}
]
我已经验证了这个设置实际上是被设置的:
gsutil cors get gs://mah-bucket
[{"maxAgeSeconds": 3600, "method": ["PUT", "POST", "GET", "HEAD", "DELETE", "OPTIONS"], "origin": ["*"], "responseHeader": ["Content-Type", "Content-MD5"]}]
以下是请求失败时的临时标头内容:
Content-MD5: Ug6Qj+DozqmniNxTXOYnDA==
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Origin: https://subdomain.example.com
Referer: https://subdomain.example.com/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
我已经按照这里的建议进行了操作:https://github.com/rails/rails/issues/31523
我也尝试过在隐身窗口中打开,因此它不会缓存任何以前的预检请求。
更新: 我已经将问题缩小到使用Google服务的ActiveStorage边缘情况。正常的文件上传表单可以使用Amazon S3和Google GCS服务。使用ActiveStorage DirectUploadController js进行上传可以使用Amazon,但无法使用Google。
每种情况下发出的请求都相同,除了服务之间的一些认证差异外,但是预检请求的响应是不同的。这是S3预检请求的响应:
Access-Control-Allow-Headers: content-md5, content-type
Access-Control-Allow-Methods: PUT, POST, GET, HEAD
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Content-Length: 0
Date: Tue, 24 Jul 2018 22:32:51 GMT
Server: AmazonS3
Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
x-amz-id-2: xxx/x/xxx
x-amz-request-id: xxx
这是GCS飞行前请求的响应结果:
access-control-allow-headers: Content-Type,Content-MD5
access-control-allow-methods: PUT,POST,GET,HEAD,DELETE,OPTIONS
access-control-allow-origin: *
access-control-max-age: 3600
alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
cache-control: private, max-age=0
content-length: 0
content-type: text/html; charset=UTF-8
date: Tue, 24 Jul 2018 22:43:25 GMT
expires: Tue, 24 Jul 2018 22:43:25 GMT
server: UploadServer
status: 200
x-guploader-uploadid: xxx-xxx
尽管看起来很愚蠢,但这似乎是一个大小写敏感问题。