简体   繁体   English

通过Javascript访问Amazon S3来进行CORS

[英]CORS via accessing Amazon S3 via Javascript

I have gone through all solutions mentioned in stackoverflow but yet I am not able to solve the error .I am receiving 403 Error while listing all my buckets in S3 and also getting the same error while listing objects in a particular bucket . 我已经遍历了stackoverflow中提到的所有解决方案,但仍无法解决该错误。在S3中列出我的所有存储桶时,我收到403错误,而在特定存储桶中列出对象时,我也遇到了相同的错误。

I have changed my CORS config on S3 as below 我已如下更改了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>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

But to no vain .My code is like below 但是没有白费。我的代码如下

s3=new  AWS.S3({ accessKeyId: userId ,secretAccessKey: password, sslEnabled: false, s3ForcePathStyle: true});
    function listBuckets(){
        $("#function").empty();
        $("#function").hide();
        $("#listObjectsOption").hide();
        $("#uploadFile").hide();
        s3.listBuckets(function(err,data){
      console.log(data);
    }

The Browser which I am using is Google Chrome. 我使用的浏览器是Google Chrome。

Can anyone please suggest. 任何人都可以建议。 Error Which I am getting is 我得到的错误是

aws.js:8167 OPTIONS 
XMLHttpRequest cannot load http://s3.amazonaws.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.

Also I am not able to create Bucket or take any actions. 另外,我无法创建存储桶或执行任何操作。

Probably has nothing to do with CORS because you are using the API here. 可能与CORS无关,因为您在此处使用的是API。 The user whos access/secret keys you use probably doesnt have the necessary permissions. 您使用的访问/秘密密钥用户可能没有必要的权限。 listBuckets needs a policy like this: listBuckets需要这样的策略:

{
        "Sid": "Stmt1472023667000",
        "Effect": "Allow",
        "Action": [
            "s3:ListAllMyBuckets"
        ],
        "Resource": [
            "*"
        ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM