Aws sdk angular - headObject方法的奇怪行为

时间:2017-05-12 09:14:16

标签: angularjs amazon-web-services amazon-s3

我遇到了一些来自S3类的headObject方法的奇怪问题,启用了浏览器的缓存(禁用缓存一切都很好)。

问题是当尝试使用headObject调用获取资源时,会随机返回false或true而不更改任何内容。

资源存在于存储桶中,正确的网址为https://s3-eu-west-1.amazonaws.com/wayonara-simo/_shards/_single_shard_1539048.jpeg

我的环境是Angular v2.4.9和Aws-Sdk v2.42.0,S3 CORS配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedOrigin>http://*</AllowedOrigin>
    <AllowedOrigin>https://*</AllowedOrigin>
    <AllowedOrigin>http://localhost:30300</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

其他信息:

跟踪控制台开发工具中出现的错误

XMLHttpRequest cannot load https://s3-eu-west-1.amazonaws.com/wayonara-simo/_shards/_single_shard_1539048.jpeg. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:30300' is therefore not allowed access.

XMLHttpRequest cannot load https://s3.amazonaws.com/wayonara-simo/_shards/_single_shard_1539048.jpeg. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:30300' is therefore not allowed access.

这些是网络面板中的错误:

Request URL:https://s3.amazonaws.com/_shards/_single_shard_1539048.jpeg
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:54.231.72.34:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Type:application/xml
Date:Fri, 12 May 2017 09:48:11 GMT
Server:AmazonS3
Transfer-Encoding:chunked
x-amz-id-2:nZZfgEX/kdsJjSTOiBXUIbSCfE1Q09rjuULw3peidaDzzGQieqqknUZCyYaQFr9KqUmyaN6CGrI=
x-amz-request-id:D487590B572BCEA2
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:authorization,x-amz-date,x-amz-user-agent
Access-Control-Request-Method:HEAD
Connection:keep-alive
Host:s3.amazonaws.com
Origin:http://localhost:30300
Referer:http://localhost:30300/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Request URL:https://s3.amazonaws.com/_shards/_single_shard_1539048.jpeg
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:54.231.72.34:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Type:application/xml
Date:Fri, 12 May 2017 09:48:12 GMT
Server:AmazonS3
Transfer-Encoding:chunked
x-amz-id-2:Uux+RZH1B8UjtROZAVnLDzqpADeVyeHu3cElxyddYEPI3UMacF0VMy+fPK3ka/mDs2CRCo3+Pac=
x-amz-request-id:785D5A24F89811A3
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:authorization,x-amz-date,x-amz-user-agent
Access-Control-Request-Method:HEAD
Connection:keep-alive
Host:s3.amazonaws.com
Origin:http://localhost:30300
Referer:http://localhost:30300/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Request URL:https://s3.amazonaws.com/_shards/_single_shard_1539048.jpeg
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:54.231.72.34:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Type:application/xml
Date:Fri, 12 May 2017 09:48:12 GMT
Server:AmazonS3
Transfer-Encoding:chunked
x-amz-id-2:ttV1ZuiAIYNWJGa3MGTbO3BDiiQ2Pcby2z/VSaqEvnlYEzfAyGc4FQAWX44OWWy6FuKmRUaUSN8=
x-amz-request-id:9079F8A97F77F858
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:authorization,x-amz-date,x-amz-user-agent
Access-Control-Request-Method:HEAD
Connection:keep-alive
Host:s3.amazonaws.com
Origin:http://localhost:30300
Referer:http://localhost:30300/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Request URL:https://s3.amazonaws.com/_shards/_single_shard_1539048.jpeg
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:54.231.72.34:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Type:application/xml
Date:Fri, 12 May 2017 09:48:12 GMT
Server:AmazonS3
Transfer-Encoding:chunked
x-amz-id-2:kfOi2aYqtvg6paYr6GPsim8DIBffv3APlFjnXzKhBQiuVQNJkalt0kPQM8XggGUo67oJim9WSrs=
x-amz-request-id:22BF45BC5DD15C5A
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:authorization,x-amz-date,x-amz-user-agent
Access-Control-Request-Method:HEAD
Connection:keep-alive
Host:s3.amazonaws.com
Origin:http://localhost:30300
Referer:http://localhost:30300/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

感谢任何帮助,谢谢

0 个答案:

没有答案