简体   繁体   中英

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=

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM