gpt4 book ai didi

javascript - 制作我的第一个 listObjects from Amazon S3 -- Classic "' Access-Control-Allow-Origin'"遇到

转载 作者:行者123 更新时间:2023-11-29 16:13:25 25 4
gpt4 key购买 nike

这是我到目前为止所做的。

使用免费帐户设置 S3,用

硬编码我的访问 key
AWS.config.update({
accessKeyId: 'hidden',
secretAccessKey: 'hidden'
});

AWS.config.region = 'us-west-2';
var myAWS = new AWS.S3();
myAWS.listObjects({Bucket: "anothertestbucketalexwait"}, function(error, data) {
console.log("Arguments!", arguments);
});

得到

XMLHttpRequest cannot load https://anothertestbucketalexwait.s3-us-west-2.amazonaws.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "http://localhost:9000" is therefore not allowed access.

在调用 listObjects() 时。

阅读 Chrome 不支持来自本地主机的 CORS(使用 yeoman/'localhost:9000')。我设置了一个本地开发 apache 服务器,所以我的主机名是 s3test.local

XMLHttpRequest cannot load https://anothertestbucketalexwait.s3-us-west-2.amazonaws.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s3test.local' is therefore not allowed access.

还是不行....

我有

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
</CORSConfiguration>

在相关存储桶的 CORS 配置下。

我还能尝试什么?

最佳答案

我也遇到了同样的问题。通过添加解决它

<AllowedHeader>*</AllowedHeader>

相关存储桶的 CORS 配置

因此,我用于直接上传到 S3 存储桶的完整 CORS 配置现在是:

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

我是初学者,所以非常欢迎任何关于这样做的安全影响的评论!

关于javascript - 制作我的第一个 listObjects from Amazon S3 -- Classic "' Access-Control-Allow-Origin'"遇到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com