Skip to content

Instantly share code, notes, and snippets.

@BarisGece
Created March 18, 2018 13:36
Show Gist options
  • Save BarisGece/6f84076bbc2c10362d88b895b6ba4982 to your computer and use it in GitHub Desktop.
Save BarisGece/6f84076bbc2c10362d88b895b6ba4982 to your computer and use it in GitHub Desktop.
//AWS SDK 1.x.x
final PutObjectRequest putRequest = new PutObjectRequest(s3bucket, targetDirectory + “/” + file.getName(), file).withCannedAcl(CannedAccessControlList.PublicRead);
final Upload upload = transferManager.upload(putRequest);
//AWS SDK 2.0 — with ContentType
String fileType = Files.probeContentType(file);
final S3Client s3client;
s3client.putObject(PutObjectRequest.builder().bucket(s3bucket).key(targetDirectory + FileSystems.getDefault().getSeparator() + file.getFileName()).acl(ObjectCannedACL.PUBLIC_READ).contentType(fileType).build(),RequestBody.of(file));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment