When one uploads an object to a S3 bucket.
Is there an API to check if the upload was successful ?
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard()
.with* ...
.build();
PutObjectResult result = this.amazonS3.putObject(s3BucketName, s3Key, file);
I read some solutions where
- the MD5 checksum is compared to the file's MD5 signature
- or the last modified date is compared
PS : I came from this old question How can I get upload success status with Amazon Web Services?
CodePudding user response:
Is there an API to check if the upload was successful ?
If no exception was thrown then it means it was successful.
CodePudding user response:
OK, I created this method handling exception ( thanks to @Adam Siemion )
public boolean uploadToS3(String s3BucketName, String s3Key, File file) {
try {
this.amazonS3Client.putObject(s3BucketName, s3Key, file);
return true;
} catch (AmazonServiceException e) {
return false;
} catch (SdkClientException e) {
return false;
}
}
Amazon S3 never stores partial objects; if during this call an exception wasn't thrown, the entire object was stored.