0
votes

I have been stuck on this for ages. I see others have had the same problem, but I cannot fix it.

I am developing an Android app, which takes a picture from the camera, and uploads it the a bucket on Amazon S3. Here is my code:

  CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(),    /* get the context for the application */
                "MY_POOL_ID",    /* Identity Pool ID */
                Regions.US_EAST_1           /* Region for your identity pool--US_EAST_1 or EU_WEST_1*/
        );


        // Create an S3 client
        AmazonS3 s3 = new AmazonS3Client(credentialsProvider);

        s3.setRegion(Region.getRegion(Regions.US_EAST_1));

        TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());

        TransferObserver observer = transferUtility.upload(
                MY_BUCKET,     /* The bucket to upload to */
                OBJECT_KEY,    /* The key for the uploaded object */
                f        /* The file where the data to upload exists */
        );

I have created a bucket. The file f, I converted a Bitmap from the camera to a file. My Pool ID works, if I change it I get an error pool not found; same with the bucket. However every time I try to upload I get this error:

Failed to upload: 11 due to Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: FD1B30F)

I am a beginner with Amazon S3, and I am following their instructions again and again, but I cannot fix this.

I have this in manifest:

<service


android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
        android:enabled="true" />

and the correct permissions.

What do I need to do to correct this?

2
What's the full error message?Yangfan
Maybe you want to give a try using example here : stackoverflow.com/questions/27096717/…mootmoot

2 Answers

1
votes

Check your bucket permissions, try to open it up completely and see if you are able to access it through Android's SDK.

Check out the policy generator that AWS provides to help you with that:

http://awspolicygen.s3.amazonaws.com/policygen.html

-3
votes

The answer to my question is that this problem happen when I tested my app on my device, Nexus 5. When I used am emulater (Genymotion) it working. However why it didn't work on my real device I dont' know.