我正在使用对象的Key和删除标记的VersionID尝试删除标记的deleteObject请求。
由于CORS,浏览器(Chrome 34.0.1847.11)向以下位置发送OPTIONS预检请求: http://bucket.s3-us-west-2.amazonaws.com/Folder/File.ext?versionId=0123456789
Amazon S3使用以下XML正文响应400(错误请求):
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>This operation does not accept a version-id.</Message>
<ArgumentValue>0123456789</ArgumentValue>
<ArgumentName>versionId</ArgumentName>
<RequestId>12345</RequestId>
<HostId>1122334455</HostId>
</Error>
因为XMLHttpRequest返回400(错误请求),所以DELETE请求永远不会被执行。我的印象是AWS没有正确处理选项请求。如果有解决方法,那就太棒了!
我当前的CORS政策是:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
仅供参考:我正在使用AWS SDK for JS 2.0.0-rc10
提前谢谢。
编辑1 :
我尝试添加<AllowedMethod>OPTIONS</AllowedMethod>
但亚马逊返回Found unsupported HTTP method in CORS config. Unsupported method is OPTIONS
编辑2 :
OPTIONS请求/响应标头:
Remote Address: *********:443
Request URL: https://bucket.s3-us-west-2.amazonaws.com/path/to/file_name?versionId=0123456789
Request Method: OPTIONS
Status Code: 400 Bad Request
Request Headers
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Access-Control-Request-Headers: x-amz-user-agent, x-amz-security-token, x-amz-date, authorization, content-type
Access-Control-Request-Method: DELETE
Cache-Control: no-cache
Connection: keep-alive
DNT: 1
Host: bucket.s3-us-west-2.amazonaws.com
Origin: https://website.com
Pragma: no-cache
Referer: https://website.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.60 Safari/537.36
Query String Parameters
versionId: 0123456789
Response Headers
Access-Control-Allow-Headers: x-amz-user-agent, x-amz-security-token, x-amz-date, authorization, content-type
Access-Control-Allow-Methods: HEAD, GET, PUT, POST, DELETE
Access-Control-Allow-Origin: *
Connection: close
Content-Type: application/xml
Date: Tue, 18 Mar 2014 23:59:15 GMT
Server: AmazonS3
Transfer-Encoding: chunked
Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
x-amz-id-2: *************************
x-amz-request-id: ***********
由于OPTIONS失败,删除请求实际上并未发生。
答案 0 :(得分:29)
我刚遇到这个问题。它只发生在Chrome上。这太棒了。
解决方案是将以下内容添加到AWS中的相关<CORSRule>
配置:
<AllowedHeader>*</AllowedHeader>
这使得Chrome不会发送OPTIONS请求,一切都应该正常运行。