2

I am using Amazon s3 javascript sdk for one of my applications. I am getting the following error:

XMLHttpRequest cannot load https://s3.amazonaws.com/. Response for preflight has invalid HTTP status code 403

I see that the preflight requests are failing in my case.

I am using Angular2 for my application and I am trying to get the list of buckets. This is the code I wrote:

getBuckets(comp: any) {
        var s3 = this.getS3();
        var params = {};
        s3.listBuckets(params, function(err, response) {
            if (err) {
                console.log(err);
                console.log('error from list buckets');
            }
            else {
                comp.buckets = response.Buckets;
            }
        })
    }

this.getS3() is a method I wrote to create an S3 instance. This is how it looks:

private getS3() {
        var currentUser = this.accountInfoService.getCurrentUser();
        AWS.config.update({ accessKeyId: currentUser.accessKeyId, secretAccessKey: currentUser.secretAccessKey });
        var Logger = { log: function(line) { console.log(line) } };
        if (currentUser.isECS) {
            console.log(currentUser.isECS);
            var ep = new AWS.Endpoint('http://' + currentUser.endPoint);
            var s3 = new AWS.S3({ endpoint: ep, s3ForcePathStyle: true, logger: Logger, sslEnabled: false });
        }
        else {
            var s3 = new AWS.S3();
        }
        return s3;
    }

Can someone please tell me what I am doing wrong here.

UnderWood
  • 803
  • 3
  • 12
  • 23
  • Try to add the HTTP verb "OPTIONS" to the allowed request headers on the server. You need to add it in the response headers. – Legends Jun 17 '16 at 18:35
  • Thanks for the reply. But it doesn't allow me to add the OPTIONS in the response header. It says, its not a supported method. – UnderWood Jun 17 '16 at 19:35
  • try as a header not as a method, you can add this * to bypass the header restriction – Nourdine Alouane Mar 29 '17 at 22:18

0 Answers0