简体   繁体   中英

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.

Below code would get you the InputStream.

ResponseInputStream responseInputStream = s3AsyncClient.getObject(GetObjectRequest.builder()
        .bucket(bucket)
        .key(key)
        .build(),
        AsyncResponseTransformer.toBlockingInputStream())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM