AmazonS3, how to check whether it was able to download?

I wrote a short test code in Java to load a PDF file generated in memory. In this test code, I just use an array of dummy bytes, but in real use I will put the generated PDF (maximum 2-3 pages) into this byte array. Everything works: the file is downloaded and permissions are set.

However, since I am returning PutObjectResult, I was wondering how I should check it. Or is it enough to look for AmazonClientException and AmazonServiceException?

In other words: How can I verify that the download is complete and that my data is not corrupted?

    String bucket = "mybucket.example.com";
    String fileName = "2011/test/test.pdf";
    AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(
        "accessKey", "secretKey"));
    byte[] contents = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
    InputStream stream = new ByteArrayInputStream(contents);
    ObjectMetadata meta = new ObjectMetadata();
    meta.setContentLength(contents.length);
    meta.setContentType("application/pdf");
    PutObjectResult res = client.putObject(bucket, fileName, stream, meta);
    client.setObjectAcl(bucket, fileName, CannedAccessControlList.PublicRead);
+5
source share
1 answer

AWS :

  • MD5 , ( , InputStream)
  • , md5 , , AmazonClientException. [ 1188 AmazonS3Client 1.19]

, , , MD5 , , , .

AmazonClientException AmazonServiceException - , , , .

+10

All Articles