5

How can a plain InputStream be created using the S3AsyncClient for a getObject request?

The S3AsyncClient for AWS JDK 2.0 does not seem to have a function that returns a ResponseInputStream<GetObjectResponse> the same way that the S3Client synchronous client does.

The only return type available is a CompletableFuture<GetObjectResponse>, but the methods returning that type assume that the data is going to a local path.

S3AsyncClient s3AsyncClient = ...;


CompletableFuture<GetObjectResponse> response = s3AsyncClient.getObject(
    GetObjectRequest.builder()
            .bucket(bucket)
            .key(key)
            .build(),
    path));    

There is a similar stackoverflow item, but the question and answer both utilize the synchronous S3Client.

Thank you in advance for your consideration and response.

Ramón J Romero y Vigil
  • 17,373
  • 7
  • 77
  • 125

1 Answers1

3

Below code would get you the InputStream.

ResponseInputStream responseInputStream = s3AsyncClient.getObject(GetObjectRequest.builder()
        .bucket(bucket)
        .key(key)
        .build(),
        AsyncResponseTransformer.toBlockingInputStream())
Sanjay Bharwani
  • 3,317
  • 34
  • 31