Home > Net >  Check upload successfully on AWS S3
Check upload successfully on AWS S3

Time:11-04

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.

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html#putObject-com.amazonaws.services.s3.model.PutObjectRequest-

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;
    }

  }

Source:

Amazon S3 never stores partial objects; if during this call an exception wasn't thrown, the entire object was stored.

  • Related