2
votes

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

3

3 Answers

3
votes

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

0
votes

You need to specify the name of your bucket. KeyName is the place inside your specified bucket where you wanna store your file. It should something like this:

private static String bucketName = "xyz";// xyz is my bucket name at s3
private static String keyName = "upload/test/";// this is location where 
//file will be stored
private static String uploadFileName = "/home/...<localpath>.../test123";
0
votes

Ensure you have used the correct region. Changing the region from us-west-2 to us-east-1 worked for me.