Created
December 17, 2015 08:07
-
-
Save franzwong/440863dd93d3432e5267 to your computer and use it in GitHub Desktop.
Upload image to S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials("userName", "password")); | |
s3.setEndpoint("s3-ap-southeast-1.amazonaws.com"); | |
ObjectMetadata metadata = new ObjectMetadata(); | |
metadata.setContentType("image/jpeg"); | |
PutObjectRequest req = new PutObjectRequest("my-bucket", "test.jpg", new FileInputStream("/Users/user/images/test.jpg"), metadata); | |
req.withCannedAcl(CannedAccessControlList.PublicRead); | |
req.withStorageClass(StorageClass.ReducedRedundancy); | |
PutObjectResult res = s3.putObject(req); | |
System.out.println(res.getContentMd5()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment