我试图从我的浏览器上传一个文件,但它根本不起作用。
我的存储桶CORS配置为:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>在我的代码中,我发送了以下内容:
xhr.open('PUT', "http://upload.test.s3.amazonaws.com/" + uploadFile.get("dest") +'?' + "partNumber=" + (part + 1) + "&" + "uploadId=" + uploadFile.get("uploadId"), true);
xhr.setRequestHeader("Authorization", uploadFile.get("authorization"));
xhr.setRequestHeader("x-amz-date", uploadFile.get("date"));
xhr.setRequestHeader("Content-Type", uploadFile.get("rawFile").type);
xhr.setRequestHeader("x-amz-acl", "public-read");
xhr.send(chunk);Ps: uploadFile有一些属性,比如来自服务器的授权密钥和uploadId。
当上传开始时,我通过了OPTIONS请求,但Put请求在几秒钟后中止(通常是在发送一定百分比的内容后4-5秒)。不幸的是,它在没有反馈的情况下中止了。有人知道会发生什么吗?
谢谢!
编辑:基本上我使用https://github.com/LearnBoost/knox从分块上传中获取UploadId (如果我在整个上传操作中使用服务器,它是有效的)
发布于 2013-12-02 06:38:23
看起来服务器不能使用通配符(即"*"),如果你使用CORS授权:检查this。
您是否尝试过在存储桶的AllowedOrigin报头中指定请求域?
https://stackoverflow.com/questions/14943561
复制相似问题