I am trying to upload files on Amazon s3 bucket in a very simple way, but it gives error if the file name consists of "(" or ")", i dont want remove or replace these braces as they are required for my case
Code:
AWSCredentials awsCredentials = new BasicAWSCredentials("accessKey", "secretKey");
AmazonS3 s3 = new AmazonS3Client(awsCredentials);
String fileName = "TEST_FILE_(NAME).pdf";
String directorykey = "path/to/amazon/directory";
File file = new File(/* path_to_file + */ fileName);
try {
s3.putObject(bucketName, directorykey+"/"+fileName , file);
} catch (AmazonServiceException e) {
LOG.fatal("Failed to store file to bucket: " , e);
} catch (AmazonClientException e) {
LOG.fatal("Failed to store file to bucket: " , e);
}
ERROR:
Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: tx000000000000002e9edee-005a4ed3d2-2213a2-uky-campus-1; S3 Extended Request ID: 123456789)
Name of the file TEST_FILE_(NAME).pdf
won't be used here - this is path to a local file,
S3 isn't actually a filesystem, it's more like a big (hash table) associative array. The "Bucket" is the name of the hash table, and the "Key" is the key ( from here )
String fileName = "TEST_FILE_(NAME).pdf";
String directorykey = "path/to/amazon/directory";
// make sure, that the file exists in a location - provide a path to a file
File file = new File(/* path_to_file + */ fileName);
try {
s3.putObject(bucketName, directorykey + "/" + fileName , file);
} catch (AmazonServiceException e) {
LOG.fatal("Failed to store file to bucket: " , e);
} catch (AmazonClientException e) {
LOG.fatal("Failed to store file to bucket: " , e);
}
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.