Sanjay Bhalani
Sanjay Bhalani

Reputation: 2474

Authorization issue when uploading image to the s3 bucket using Android

I have used the code below for uploading an image to the s3 bucket using Android.

AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials(context.getString(R.string.accesskey),context.getString(R.string.secretkey)));
PutObjectResult result = s3client.putObject(new PutObjectRequest(bucketName, amazonfilepath, file).withAccessControlList(acl));

When I create bucket in Asia Pacific (Singapore) regions then it works fine. But I have to change regions of bucket to Asia Pacific (Mumbai) then it throws below error.

Amazon s3 image uploading:com.amazonaws.services.s3.model.AmazonS3Exception: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256. (Service: Amazon S3; Status Code: 400; Error Code: InvalidRequest; Request ID: 85D0346520B14007), S3 Extended Request ID: gC67avqeowqS4+X+2qkBxzLxfj9ABVV22zWgPcm/rZBKC0RIso201+eMsvBsqdnH+8n0V9RI0J8=

Upvotes: 3

Views: 643

Answers (2)

Logesh R
Logesh R

Reputation: 305

Confirmed, Updating the sdk to latest version fixed it. in my case,

implementation 'com.amazonaws:aws-android-sdk-core:2.6.13'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.13'

if you have the same issue, check the aws sdk version in your app level build.gradle file.

Just answering incase someone comes here searching for it.

Upvotes: 0

Sanjay Bhalani
Sanjay Bhalani

Reputation: 2474

I was used below SDK for same.

compile 'com.amazonaws:aws-android-sdk-s3:2.2.13' 

now used below version of sdk than it will work fine.

compile 'com.amazonaws:aws-android-sdk-s3:2.4.0'

Upvotes: 4

Related Questions