Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an S3Object InputStream from a GetObjectResponse in AWS Java SDK 2 Using S3AsyncClient?

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.

like image 613
Ramón J Romero y Vigil Avatar asked Apr 29 '26 15:04

Ramón J Romero y Vigil


1 Answers

Below code would get you the InputStream.

ResponseInputStream responseInputStream = s3AsyncClient.getObject(GetObjectRequest.builder()
        .bucket(bucket)
        .key(key)
        .build(),
        AsyncResponseTransformer.toBlockingInputStream())
like image 170
Sanjay Bharwani Avatar answered May 02 '26 04:05

Sanjay Bharwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!