1
votes

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"));
2
The aws s3 sync command is a Python program that loops through each file and copies each file individually. There is no AWS API for copying multiple files in one call.John Rotenstein

2 Answers

2
votes

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

1
votes

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