I'm using software.amazon.awssdk.transfer.s3.S3TransferManager to download files from the s3 bucket to the ECS instance. Below is the code.
final GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket(bucket)
.key(key)
.versionId(versionId)
.build();
final DownloadFileRequest downloadFileRequest = DownloadFileRequest.builder()
.destination(destination)
.getObjectRequest(getObjectRequest)
.build();
transferManager.downloadFile(downloadFileRequest);
It works well when I give a file name without space in it. But it fails with the below error if the file name contains space in it.
java.util.concurrent.CompletionException: software.amazon.awssdk.services.s3.model.S3Exception: The specified version does not exist.
If I don't pass the version in the input request, I get the below error.
java.util.concurrent.CompletionException: software.amazon.awssdk.services.s3.model.NoSuchKeyException: The specified key does not exist.
I then tried using S3 getObject API like below. Still getting the same issue.
final GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket(bucket)
.key(key)
.versionId(versionId)
.build();
s3Client.getObject(getObjectRequest, destination);
How to fix this issue?