Android AWS S3 Access Denied

2020-07-27 05:38发布

问题:

I'm trying to simply upload a file to an S3 bucket with my Android app. I've tried everything they've said, did all the examples and used a third party library. Nothing works. I keep getting an Access Denied error when I run this code:

       AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials("MY KEY", "MY SECRET" ) );
        s3Client.createBucket("evenatir");
        PutObjectRequest por = new PutObjectRequest("BUCKETNAME", "VIDEONAME", new java.io.File("/storage/emulated/0/Movies/outterlimits20.mp4") );
        s3Client.putObject( por );

It returns this error message at the createBucket(); method:

     Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: F2871EBB4091D6D9), S3 Extended Request ID: gqR4PhULERMiGxVTbzzC71mDoeKZxyRu9mLYMcF+wPaFN8KT6VrqyU+k6i7/Pee0

I also used the Android simpl3r library and actually, to my surprise, got past the Access Denied error but, of course, got some XML not well formed error to which AWS has yet to do anything about. I'm completely stuck, I just want to upload a file to my S3 bucket!

回答1:

Make sure the bucketname your are passing has to be created already before uploading any file.

Instead of throwing bucket not found exception, aws throws access denied exception.

Hope this will help you.