Raymond Chenon
Raymond Chenon

Reputation: 12722

Check upload successfully on AWS S3

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

PS : I came from this old question How can I get upload success status with Amazon Web Services?

Upvotes: 1

Views: 3192

Answers (2)

Raymond Chenon
Raymond Chenon

Reputation: 12722

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.

Upvotes: 2

Adam Siemion
Adam Siemion

Reputation: 16039

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-

Upvotes: 1

Related Questions