Balu
Balu

Reputation: 161

Upload a folder to an S3 bucket using java aws sdk

I'm trying to upload an entire folder to AWS S3 bucket. I'm successful at uploading individual files, but couldn't find a way to upload the entire folder. AWS CLI has an option called sync, does and equivalent methods available in Java SDK?

Sample code for uploading individual objects is as below (only part)

final PutObjectRequest dashboardUploadRequest = PutObjectRequest.builder()
                        .bucket(aws.getApplihealthReportBucket())
                        .key(projectName + "/"+ executionConfig.getTestType() +"/" + aws.getS3Folder() + "/index.html").build();

S3Client s3 = S3Client.builder().credentialsProvider(credentialsProvider).build()
s3.putObject(dashboardUploadRequest, Paths.get(resultsDirectory + "/extent.html"));

Upvotes: 2

Views: 3325

Answers (2)

Vikdor
Vikdor

Reputation: 24124

The TransferManager API in Java SDK provides methods to upload a directory to S3.

Upvotes: 1

Tuan Vo
Tuan Vo

Reputation: 2065

There are no way to upload folder directly to s3. Only forearch and upload file by file.

Or using CLI https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html

Upvotes: 2

Related Questions