AmazonS3, how to check if the upload succeeded?

后端 未结 1 511
灰色年华
灰色年华 2021-01-05 07:37

I wrote a short test code in Java to upload a PDF file generated in memory. In this test code I just use a dummy byte array, but in the real use I will put a generated PDF (

相关标签:
1条回答
  • 2021-01-05 07:53

    I've looked the source code of AWS and debugged it and discovered the following:

    • If MD5 is not provided it's calculated (works either for real files and InputStream)
    • When the upload is finished md5 client side and server side are compared and if they differ an AmazonClientException is thrown. [line 1188 of AmazonS3Client 1.19]

    In other words, to answer my own question, it's enough to listen for the exceptions because also the MD5 of the data uploaded is checked, so if there was a corruption an exception would be raised.

    AmazonClientException and AmazonServiceException are unchecked exceptions, so it's important to remember to listen for them since the compiler won't force you to.

    0 讨论(0)
提交回复
热议问题