Interface DownloadDirectoryRequest.Builder

  • Method Details

    • destination

      DownloadDirectoryRequest.Builder destination(Path destination)
      Specifies the destination directory to which files should be downloaded.
      Parameters:
      destination - the destination directorÏy
      Returns:
      This builder for method chaining.
    • bucket

      The name of the bucket to download objects from.
      Parameters:
      bucket - the bucket name
      Returns:
      This builder for method chaining.
    • filter

      Specifies a filter that will be used to evaluate which objects should be downloaded from the target directory.

      You can use a filter, for example, to only download objects of a given size, of a given file extension, of a given last-modified date, etc. See DownloadFilter for some ready-made implementations. Multiple DownloadFilters can be composed together via the and and or methods.

      By default, if no filter is specified, all objects will be downloaded.

      Parameters:
      filter - the filter
      Returns:
      This builder for method chaining.
      See Also:
    • downloadFileRequestTransformer

      DownloadDirectoryRequest.Builder downloadFileRequestTransformer(Consumer<DownloadFileRequest.Builder> downloadFileRequestTransformer)
      Specifies a function used to transform the DownloadFileRequests generated by this DownloadDirectoryRequest. The provided function is called once for each file that is downloaded, allowing you to modify the paths resolved by TransferManager on a per-file basis, modify the created GetObjectRequest before it is passed to S3, or configure a TransferRequestOverrideConfiguration.

      The factory receives the DownloadFileRequests created by Transfer Manager for each S3 Object in the S3 bucket being downloaded and returns a (potentially modified) DownloadFileRequest.

      Usage Example:

      // Add a LoggingTransferListener to every transfer within the download directory request
      
      DownloadDirectoryRequest request =
          DownloadDirectoryRequest.builder()
              .destination(Paths.get("."))
              .bucket("bucket")
              .downloadFileRequestTransformer(request -> request.addTransferListener(LoggingTransferListener.create()))
              .build();
      
      DownloadDirectoryTransfer downloadDirectory = transferManager.downloadDirectory(request);
      
      // Wait for the transfer to complete
      CompletedDownloadDirectory completedDownloadDirectory = downloadDirectory.completionFuture().join();
      
      // Print out the failed downloads
      completedDownloadDirectory.failedDownloads().forEach(System.out::println);
      
      Parameters:
      downloadFileRequestTransformer - A transformer to use for modifying the file-level download requests before execution
      Returns:
      This builder for method chaining
    • listObjectsV2RequestTransformer

      DownloadDirectoryRequest.Builder listObjectsV2RequestTransformer(Consumer<ListObjectsV2Request.Builder> listObjectsV2RequestTransformer)
      Specifies a function used to transform the ListObjectsV2Requests generated by this DownloadDirectoryRequest. The provided function is called once, allowing you to modify ListObjectsV2Request before it is passed to S3.

      The factory receives the ListObjectsV2Requests created by Transfer Manager and returns a (potentially modified) ListObjectsV2Request.

      Usage Example:

      
      DownloadDirectoryRequest request =
          DownloadDirectoryRequest.builder()
              .destination(Paths.get("."))
              .bucket("bucket")
              .listObjectsV2RequestTransformer(request -> request.encodingType(newEncodingType))
              .build();
      
      DownloadDirectoryTransfer downloadDirectory = transferManager.downloadDirectory(request);
      
      // Wait for the transfer to complete
      CompletedDownloadDirectory completedDownloadDirectory = downloadDirectory.completionFuture().join();
      
      // Print out the failed downloads
      completedDownloadDirectory.failedDownloads().forEach(System.out::println);
      

      Prefix: ListObjectsV2Request's prefix specifies the key prefix for the virtual directory. If not provided, all subdirectories will be downloaded recursively

      See Organizing objects using prefixes

      When a non-empty prefix is provided, the prefix is stripped from the directory structure of the files.

      For example, assume that you have the following keys in your bucket:

      • sample.jpg
      • photos/2022/January/sample.jpg
      • photos/2022/February/sample1.jpg
      • photos/2022/February/sample2.jpg
      • photos/2022/February/sample3.jpg
      Given a request to download the bucket to a destination with a prefix of "/photos" and destination path of "test", the downloaded directory would like this
         
            |- test
               |- 2022
                    |- January
                       |- sample.jpg
                    |- February
                       |- sample1.jpg
                       |- sample2.jpg
                       |- sample3.jpg
         
       

      Delimiter: ListObjectsV2Request's delimiter specifies the delimiter that will be used to retrieve the objects within the provided bucket. A delimiter causes a list operation to roll up all the keys that share a common prefix into a single summary list result. It's null by default. For example, assume that you have the following keys in your bucket:

      • sample.jpg
      • photos-2022-January-sample.jpg
      • photos-2022-February-sample1.jpg
      • photos-2022-February-sample2.jpg
      • photos-2022-February-sample3.jpg
      Given a request to download the bucket to a destination with delimiter of "-", the downloaded directory would look like this
         
            |- test
               |- sample.jpg
               |- photos
                   |- 2022
                       |- January
                           |- sample.jpg
                       |- February
                           |- sample1.jpg
                           |- sample2.jpg
                           |- sample3.jpg
         
       
      Parameters:
      listObjectsV2RequestTransformer - A transformer to use for modifying ListObjectsV2Request before execution
      Returns:
      This builder for method chaining