2013-02-26 9 views
5

Potrzebuję wysłać folder z podfolderami na amazon s3. Próbuję przesłać z tym snipetem.Jak wgrać folder z podfolderem do 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())); 
     } 
    } 

Ale ten kod tworzenie pełnych ścieżek plików z ("/ home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf"). Jak przesłać go ze ścieżką ("/ planów/eota7tas0cdlg2ufq5mlke7olf/{podfolderów i plików}")

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; 
    } 

Odpowiedz

12

Pan spojrzał na TransferManager w AWS SDK for Java? Możesz użyć do tego metody uploadDirectory. Jawadok to here. W zasadzie możesz zrobić coś takiego:

transferManager.uploadDirectory(bucketName, "plans/eota7tas0cdlg2ufq5mlke7olf/", new File("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf/"), true); 
1

Napisałem własną drogę.

 List<File> files = new LinkedList<File>(); 
     listFiles(new File("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf"), files, true); 
     for (File f : files) { 
      String key = f.getAbsolutePath().substring(new File("/home/rmuhamedgaliev/tmp/eota7tas0cdlg2ufq5mlke7olf").getAbsolutePath().length() + 1) 
       .replaceAll("\\\\", "/"); 
      amazonS3Client.putObject("****", "plans/eota7tas0cdlg2ufq5mlke7olf/" + key, f); 
     } 
+0

Chcę przesłać wszystkie pliki, które są obecne w jednym folderze, takie jak Załóżmy, że mam folderu nazwa „TestMech”, która zawiera liczbę zdjęć, że wszystkie zdjęcia muszę przesłać za pomocą wskaźnika postępu jest to możliwe i w jaki sposób –