Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid "Networking Error: Network Failure" when downloading a file from AWS S3 bucket?

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>

like image 476
user3337896 Avatar asked Feb 21 '14 15:02

user3337896


People also ask

How do I download data from S3 bucket?

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.

How can you securely upload or download your data to from the S3 service?

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.

How do I get permission to download a S3 bucket?

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.


1 Answers

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>
like image 180
user3337896 Avatar answered Oct 16 '22 02:10

user3337896