Skip to content

Instantly share code, notes, and snippets.

@atroche
Created May 16, 2019 06:07
Show Gist options
  • Save atroche/7841124818e3f2e8fd44ecd720d3e9ef to your computer and use it in GitHub Desktop.
Save atroche/7841124818e3f2e8fd44ecd720d3e9ef to your computer and use it in GitHub Desktop.
protected void copyFileToS3(File file, String contentType, String bucket, String key) {
PutObjectRequest request = new PutObjectRequest(bucket, key, file);
request.setCannedAcl(CannedAccessControlList.Private);
request.setStorageClass(StorageClass.ReducedRedundancy);
request.setMetadata(new ObjectMetadata());
request.getMetadata().setContentType(contentType);
request.getMetadata().setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
request.getMetadata().setCacheControl(String.format("public, max-age=%d", Duration.standardDays(90).getStandardSeconds()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment