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.