【发布时间】:2013-02-11 23:33:57
【问题描述】:
我需要在 amazon 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;
}
【问题讨论】:
标签: java file-upload amazon-s3 amazon