错误:“XMLHttpRequest无法加载http://my-bucket.storage.googleapis.com/my-object?upload_id=my_upload_id
。请求的资源上不存在”Access-Control-Allow-Origin“标头。因此,不允许原始http://my-uri
访问。”
我使用服务帐户身份验证初始化服务器端控制器上的可恢复上载并返回upload_id。
我尝试使用JSON API& XML API没有成功。上传文件在GCS上完全转移,但请求结果为: “No'Access-Control-Allow-Origin'标头出现在请求的资源上。”
我使用XHR2& FormData对象。
$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
that.updateProgressBarStatus(percentComplete);
}
}, false);
return xhr;
},
type: 'PUT',
url: that.resumeUri,
data: that.formData,
cache: false,
crossDomain: true,
processData: false,
dataType: "xml"
我在我的存储桶上设置CORS配置以接受所有uri
Bucket CORS配置:
<?xml version="1.0" encoding="UTF-8"?>
<CorsConfig>
<Cors>
<Origins>
<Origin>*</Origin>
</Origins>
<Methods>
<Method>GET</Method>
<Method>HEAD</Method>
<Method>DELETE</Method>
<Method>PUT</Method>
<Method>POST</Method>
</Methods>
<ResponseHeaders>
<ResponseHeader>*</ResponseHeader>
</ResponseHeaders>
<MaxAgeSec>3600</MaxAgeSec>
</Cors>
</CorsConfig>
我有一个状态代码为200的预检请求'OPTIONS'和带有http://my-uri
值的'Access-Control-Allow-Origin'标题。
PUT请求标题:
(warning) Provisional headers are shown
Accept:application/json, text/javascript, */*; q=0.01
Content-Type:multipart/form-data
Origin:http://my-uri
Referer:http://my-uri/upload
User-Agent:xxx
X-DevTools-Emulate-Network-Conditions-Client-Id:xxx
PUT请求响应:
Hypertext Transfer Protocol
HTTP/1.1 200 OK\r\n
[Expert Info (Chat/Sequence): HTTP/1.1 200 OK\r\n]
[Message: HTTP/1.1 200 OK\r\n]
[Severity level: Chat]
[Group: Sequence]
Request Version: HTTP/1.1
Status Code: 200
Response Phrase: OK
ETag: "ddea013a6459e51f5cc6fc59ef0e41dc"\r\n
x-goog-generation: 1413473702277000\r\n
x-goog-metageneration: 1\r\n
x-goog-hash: crc32c=oMfaRA==\r\n
x-goog-hash: md5=3eoBOmRZ5R9cxvxZ7w5B3A==\r\n
x-goog-stored-content-length: 121168887\r\n
x-goog-stored-content-encoding: identity\r\n
Vary: Origin\r\n
Date: Thu, 16 Oct 2014 15:35:02 GMT\r\n
Server: UploadServer ("Built on Oct 9 2014 15:35:27 (1412894127)")\r\n
Content-Length: 0\r\n
[Content length: 0]
Content-Type: text/html; charset=UTF-8\r\n
Alternate-Protocol: 80:quic,p=0.01\r\n
\r\n
[HTTP response 2/2]
[Time since request: 0.819309000 seconds]
[Prev request in frame: 8]
[Prev response in frame: 10]
[Request in frame: 22103]
有什么建议吗?感谢名单