我需要在亚马逊 s3 上上传带有子文件夹的文件夹。我尝试用这个片段上传。
for (Path path : directoryWalk("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf/")){
if (!path.getParent().toString().equals("eota7tas0cdlg2ufq5mlke7olf")){
amazonS3Client.putObject("*****", "/plans/eota7tas0cdlg2ufq5mlke7olf/" + path.getParent().toString() + "/" + path.getFileName(), new File(path.toString()));
} else {
amazonS3Client.putObject("*******", "/plans/eota7tas0cdlg2ufq5mlke7olf/" + path.getFileName(), new File(path.toString()));
}
}
但是此代码使用("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf")创建完整路径文件。如何使用路径上传(“/plans/eota7tas0cdlg2ufq5mlke7olf/{subfolders and files}”)
private List<Path> directoryWalk(String path) throws IOException {
final List<Path> files = new ArrayList<>();
Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
files.add(file);
return FileVisitResult.CONTINUE;
}
});
return files;
}