I am using AWS S3 to access a file in my HTML5 application. Following code works fine on my laptop but it fails on the mobile device (iphone). Any help is greatly appreciated.
AWS.config.region = 'us-west-2';
var bucket = new AWS.S3({params: {Bucket: 'mybucket'}});
bucket.getObject({Key: myfile}, function (error, data) {
if (error != null) {
alert("Failed to retrieve " + myfile + " :" + error);
} else {
//alert("Loaded " + data.ContentLength + " bytes");
localStorage[myfile] = data.Body.toString();
// do something with data.body
}});
The error I get is: "http //local host Failed to retrieve foo.json :NetworkingError: Network Failure"
I have the followings CORS configuration for this bucket
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
</CORSRule>
To download an entire bucket to your local file system, use the AWS CLI sync command, passing it the s3 bucket as a source and a directory on your file system as a destination, e.g. aws s3 sync s3://YOUR_BUCKET . . The sync command recursively copies the contents of the source to the destination.
You can securely upload/download your data to Amazon S3 via SSL endpoints using the HTTPS protocol. If you need extra security you can use the Server-Side Encryption (SSE) option to encrypt data stored at rest.
Open the IAM console from the account that the IAM user belongs to. Add a policy to the IAM user that grants the permissions to upload and download from the bucket. The policy must also work with the AWS KMS key that's associated with the bucket.
I was able to get this resolved by aws tech support. Issue got resolved with the following CORSconfig:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With