I'm really new to AWS so please bear with me :(
I'm currently making a web application that has a feature for uploading photos. I want to save these photos in S3 buckets and save a reference to them in my database. I am following this guide at the moment: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html
However, I've done everything stated in the guide (or at least I hope), but when I run the app and run the createAlbum()
method, I get the error:
XMLHttpRequest cannot load https://my-bucket-name.s3-us-west-2.amazonaws.com/myalbumname/.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
I made sure that permissions allowed for all users in the Bucket permissions, I updated the CORS config as instructed by the docs, and updated the role policy as well.
This is my code in terms of credentials:
var albumBucketName = 'my-bucket-name'; //not the real value, obviously
var bucketRegion = 'us-west-2';
var IdentityPoolId = 'my-identity-pool-id'; //here, too
AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
I've been trying to find a solution with no success. Does anyone know what I need to do to fix this? Any help is greatly appreciated! Thank you.