我正在尝试执行已签名的可恢复上传到 GCS.我们的前端在初始请求中遇到了 CORS 限制:对预检请求的响应未通过访问控制检查:请求的资源上不存在Access-Control-Allow-Origin"标头.
I'm trying to perform a signed resumable upload to GCS. Our frontend is running up against CORS restrictions on the initial request: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
响应标头不显示 CORS 标头:
The response headers show no CORS headers:
alt-svc: quic=":443";马=2592000;v="44,43,39,35"缓存控制:私有,max-age=0内容长度:0内容类型:文本/html;字符集=UTF-8日期:格林威治标准时间 2018 年 11 月 13 日星期二 20:28:32到期:格林威治标准时间 2018 年 11 月 13 日星期二 20:28:32服务器:上传服务器状态:200x-guploader-uploadid: AEnB2Ups1tKbTbhPmsjrPXbIuIUyQt135AlSJ1n7-7XTwMrtQ2vUvn1WwpX3a_iusfmsXHaufdf5B3H2PzmDONs2wW7tKkLarYoxrVyWalhaX6FzGQPoRW0
调试中,我发送了一个模仿前端请求的 curl 请求:
Debugging, I sent a curl request mimicking our frontend's request:
curl -H "Access-Control-Request-Headers: content-type,x-goog-resumable" -H访问控制请求方法:POST"-H "来源:www.example" -X 选项 -I storage.googleapis/bucket/...
同样,响应不包含 CORS 响应标头:
Again, the response contains no CORS response headers:
HTTP/2 200x-guploader-uploadid: AEnB2UqwKiRSJjHjF9mzsZRMODdQmF6xhUAhdeEenuD0_WXmxpVA6n0i_HWY2NOJxvXS2t_I4IoFW_yvz6lssMz_HVmvlswL5NilGC3wE2YT0-L9aD7Pf1Q日期:格林威治标准时间 2018 年 11 月 13 日星期二 21:39:53到期:格林威治标准时间 2018 年 11 月 13 日星期二 21:39:53缓存控制:私有,max-age=0内容长度:0服务器:上传服务器内容类型:文本/html;字符集=UTF-8alt-svc: quic=":443";马=2592000;v="44,43,39,35"
我已经使用 gsutil cors set cors.json gs://bucket 设置了我的存储桶 CORS 设置,其中 cors.json 包含 [{"maxAgeSeconds": 3600, "method":["GET", "POST", "PUT", "OPTIONS"], "origin": ["*"]}]
I've set my bucket CORS settings with gsutil cors set cors.json gs://bucket where cors.json contains [{"maxAgeSeconds": 3600, "method": ["GET", "POST", "PUT", "OPTIONS"], "origin": ["*"]}]
我错过了什么吗?
推荐答案我找到了解决方案.我不得不将 x-goog-resumable 添加到响应头列表中.
I have found a solution. I had to add x-goog-resumable to the list of response headers.
我的 CORS 文件是
My CORS file is
[ { "origin": ["*"], "responseHeader": [ "Content-Type", "Access-Control-Allow-Origin", "x-goog-resumable"], "method": ["GET", "HEAD", "DELETE", "POST", "OPTIONS"], "maxAgeSeconds": 3600 } ]至少预检开始工作
更多推荐
Google Cloud Storage 签名 URL 的预检未返回 CORS 响应标头
发布评论