Rin*_*iev 6 java amazon file-upload amazon-s3
我需要在亚马逊s3上使用子文件夹上传文件夹.我尝试使用此snipet上传.
    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;
    }
Wad*_*nko 13
您是否查看TransferManager过AWS SDK for Java?您可以使用此uploadDirectory方法.javadoc就在这里.从本质上讲,你可以这样做:
transferManager.uploadDirectory(bucketName, "plans/eota7tas0cdlg2ufq5mlke7olf/", new File("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf/"), true);
| 归档时间: | 
 | 
| 查看次数: | 6269 次 | 
| 最近记录: |