javaamazon-web-servicesamazon-s3aws-sdk

PermanentRedirect error while uploading to S3 bucket with aws-sdk-java


I am trying to upload a file from a java class to aws S3.

I am using the exact code as given here

The only parts I changed are these:

private static String bucketName     = "s3-us-west-2.amazonaws.com/<my-bubket-name>";
private static String keyName        = "*** Provide key ***";
private static String uploadFileName = "/home/...<localpath>.../test123";

I am not sure what to add in Provide Key . But even if I leave it this way, i get an error like this :

Error Message: The bucket is in this region: null.Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: *******) HTTP Status Code: 301 AWS Error Code: PermanentRedirect Error Type: Client


Solution

  • Instead of s3-us-west-2.amazonaws.com/<my-bucket-name> you should put <my-bucket-name>.