Am trying to upload my file via:
console.log("not broken til here");
scope.inputMemeIsFile=true;
var bucket = new AWS.S3({params: {Bucket: 'townhall.images'}});
file = image.file;
console.log(file);
var params = {Key: file.name, ContentType: file.type, Body: file};
bucket.upload(params, function (err, data) {
var result = err ? 'ERROR!' : 'UPLOADED.';
console.log(result);
console.log(err);
});
However, am getting the following error:
XMLHttpRequest cannot load https://s3.amazonaws.com/<BUCKETNAME>/favicon.jpg. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:5000' is therefore not allowed access.
with the proceedingError: Network Failure {message: "Network Failure", code: "NetworkingError", time: Tue Feb 17 2015 13:37:06 GMT-0500 (EST), region: "us-east-1", hostname: "s3.amazonaws.com"…
}
My CORS config looks like the following and I have tried a couple things with no luck.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://*</AllowedOrigin>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Anyone have any idea whats wrong? I've looked at 5-6 similar posts but no one seems to be able to solve the problem.
Some browsers, such as Chrome, do not support
localhost
or127.0.0.1
for CORS requests.Try using instead:
http://lvh.me:5000/
See https://stackoverflow.com/a/10892392/1464716 for more.
I would suggest you start with an open test configuration and then modifying it to your needs:
Then check your bucket permissions and your
AWS
configuration (accessKeyId
,secretAccessKey
, andregion
) since none of these are present in your snippet.For testing, go to your IAM Management Console and create a new IAM user named
prefix-townhall-test
then create a group with this simple policy that grants access to a bucket:Make sure the user you created is using the new group with this policy.
Now create a simple test script like the one used on amazon this:
HTML
CODE (on DOM ready)
Try
<AllowedOrigin>*</AllowedOrigin>
, without protocol.If it has no effect – you probably have problem on client side.
Have you tried specifying your origin instead of using wildcard. I'm pretty sure we had similar problems in the past.