· 7 years ago · Aug 31, 2018, 07:30 PM
1AmazonS3, how to check if the upload succeeded?
2String bucket = "mybucket.example.com";
3 String fileName = "2011/test/test.pdf";
4 AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(
5 "accessKey", "secretKey"));
6 byte[] contents = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
7 InputStream stream = new ByteArrayInputStream(contents);
8 ObjectMetadata meta = new ObjectMetadata();
9 meta.setContentLength(contents.length);
10 meta.setContentType("application/pdf");
11 PutObjectResult res = client.putObject(bucket, fileName, stream, meta);
12 client.setObjectAcl(bucket, fileName, CannedAccessControlList.PublicRead);