'How to upload folder with sub folder to Amazon S3
I need upload a folder with sub folders on Amazon S3.
I create this code saverepertoire2 But this code upload only files in the folder.
public String uploadFolder1(Path filePath) {
PutObjectRequest objectRequest = PutObjectRequest.builder()
.bucket(bucketName)
.key(filePath.getFileName().toString())
.build();
// Put the object into the bucket
CompletableFuture<PutObjectResponse> future = s3AsyncClient.putObject(objectRequest,
AsyncRequestBody.fromFile(filePath));
future.whenComplete((resp, err) -> {
try {
if (resp != null) {
System.out.println("Object uploaded. Details: " + resp);
} else {
err.printStackTrace();
}
} finally {
// s3Client.close();
}
});
future.join();
return "Your file " + filePath + " was successfully uploaded ASync";
}
public void saverepertoire2(String path) throws IOException {
Path path1 = Paths.get(path);
try (Stream<Path> paths = Files.walk(path1)) {
paths.filter(Files::isRegularFile).forEach(x -> uploadFolder1(x));
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
