I am trying to upload a csv file to S3 bucket. The code runs successfully but when I check the bucket, the file with Access Key as its name is uploaded. I have to rename the file manually to check its content.
Is there a way where I could rename the file programmatically only or may be the file name does not change automatically while uploading?
Please check the code below:
public class AwsFileUploader {
private static String bucketName = "mybucket";
private static String accessKey = "my-access-key";
private static String secretKey = "my-secret-key";
private static String uploadFileName = "CompressionScore/compression_score_09-04-2015.csv";
public static void main(String[] args) throws IOException {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3client = new AmazonS3Client(credentials);
try {
System.out.println("Uploading a new object to S3 from a file\n");
File file = new File(uploadFileName);
System.out.println(file.getName()); //prints - compression_score_09-04-2015.csv
s3client.putObject(new PutObjectRequest(bucketName, accessKey, file));
System.out.println("File successfully uploaded");
} catch (AmazonServiceException ase) {
ase.printStackTrace();
} catch (AmazonClientException ace) {
ace.printStackTrace();
}
}
}
Ideally the file in bucket should be with the name compression_score_09-04-2015.csv but instead its AKAJI3EBMILBCWENUSA.
Could somebody guide as to what should be done?