File is not completely downloaded using Amazon S3 Transfer Manager AWS SDK Java 2

0

I'm facing a strange issue with the API I am trying to build, specifically when trying to download a file. Here's what's happening:

When I run the API on my local machine and request to download a file, everything works fine and the whole file gets downloaded without any problems. However, when I try to make the same request on staging where the API is deployed, only a small part of the file is downloaded.

The Amazon S3 async client is set up the same way for both my local environment and the staging environment, except for the credentials provider object. we use the S3 Transfer Manager to handle file downloads

here is the code to download a file

public Long downloadFile(
      String key, String downloadedFileWithPath) {
    if (key == null || key.isEmpty() || downloadedFileWithPath == null
      || downloadedFileWithPath.isEmpty()) {
      throw new IllegalArgumentException(
        "key and downloadedFileWithPath should have a value.");
    }
    DownloadFileRequest downloadFileRequest =
        DownloadFileRequest.builder()
            .getObjectRequest(b -> b.bucket(bucketName).key(key))
            .addTransferListener(LoggingTransferListener.create())
            .destination(Paths.get(downloadedFileWithPath))
            .build();

    FileDownload downloadFile = transferManager.downloadFile(
        downloadFileRequest);

    CompletedFileDownload downloadResult = downloadFile.completionFuture()
        .join();
    return downloadResult.response().contentLength();


  }

asked 6 months ago425 views
1 Answer
0

Hello

As per my understanding, you are facing issues in downloading file using S3 Transfer Manager utility in SDK in your staging environment while the same is working in your local system.

I tried to replicate the same issue in one of my EC2 servers, where I used the code from the section Download a file from an S3 bucket in the document available here.

In my case I was able to download the file from my S3 bucket in both the scenarios -> local system and in one of my EC2 servers. I initialized the object of S3TransferManager with default settings and with custom settings. Both the scenarios worked at my end. You can read more about creating an instance of the S3 Transfer Manager from the document available here.

I request you to please check and provide few things from your end:

  1. Confirm that you are using Java SDK version 2.19.1 or a version higher than this.
  2. Confirm that you are using the latest version of aws-crt artifact dependency. You can check the latest version of aws-crt from the Maven document
  3. With S3 Transfer Manager, we also get the feature of monitoring the transfer's progress in real time. Please check and confirm if the transfer progress was fully completed or interrupted/paused in between. Check if there was any error message thrown.
  4. Please try to configure a S3 Transfer Manager with custom settings as mentioned in the document here

If you have a technical support plan with you, you can also reach out to us by creating a case from Support center and providing all the above-mentioned information as we can then access the resources in your account for better troubleshooting.

Thank You!

AWS
SUPPORT ENGINEER
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions