阅读背景:

AWS S3 Javascript在浏览器中出错

来源:互联网 

I'm trying out the AWS Javascript SDK, I wrote a simple code based on the examples to get the list of files in a bucket. But I keep getting NetworkingError: Network Failure, and can't find any references to this error in the docs.

我正在尝试使用AWS Javascript SDK,我根据示例编写了一个简单的代码来获取存储桶中的文件列表。但我不断收到NetworkingError:网络故障,并且在文档中找不到任何对此错误的引用。

I also get the same error when I try a getObject.

我尝试getObject时也遇到了同样的错误。

My code:

我的代码:

AWS.config.update({
    accessKeyId : 'myaccesskey',
    secretAccessKey : 'mysecretkey'
});
AWS.config.region = 'us-west-2';

function list(){
    var bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
      bucket.listObjects(function (err, data) {
        if (err) {
            alert(err);
        } else {
            document.getElementById('status').innerHTML = 'Loaded ' + data.Contents.length + ' items from S3';
            for (var i = 0; i < data.Contents.length; i++) {
            document.getElementById('objects').innerHTML +=
                   '<li>' + data.Contents[i].Key + '</li>';
             }
        }
      });
}

I configured CORS to accept GET from all locations.

我配置CORS以接受来自所有位置的GET。

<CORSConfiguration>
  <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

What am I missing here?

我在这里想念的是什么?

2 个解决方案

#1


3  

The list of regions and endpoints can be found here:

可在此处找到区域和端点列表:

https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

Am using your same code. Please check the below version with your code ;

我使用相同的代码。请使用您的代码检查以下版本;

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.0-rc4.min.js"></script>

Again, please double check the region. If you still receive a Network Failure error, please give me the script you're using and the bucket name so I can check on my end.

再次,请仔细检查该地区。如果您仍然收到网络故障错误,请告诉我您正在使用的脚本和存储桶名称,以便我可以检查我的结果。

Looking forward to your reply.

期待你的回复。

#2


1  

The SDK is attempting to access the bucket in the region you've configured ('us-west-2'). A networking error with S3 usually means that your bucket does not exist in the region you've configured (it is trying to connect to myBucket.s3-us-west-2.amazonaws.com).

SDK正在尝试访问您已配置的区域中的存储桶('us-west-2')。 S3的网络错误通常意味着您的存储桶在您配置的区域中不存在(它正在尝试连接到myBucket.s3-us-west-2.amazonaws.com)。

Is that where your bucket is? If you did not select a region when you created your bucket, it is probably in the "US Standard" region, which maps to 'us-east-1' in the SDK.

你的水桶在哪里?如果您在创建存储桶时未选择区域,则可能位于“美国标准”区域,该区域映射到SDK中的“us-east-1”。


分享到: