Skip to content

Example code in original blog post (S3AsyncClient.getObject) not correct #381

Description

@rmuller

This example code in the original blog post is not correct, see the same code in github repo:

public static void main(String[] args) {
    final S3AsyncClient client = S3AsyncClient.create();
    final CompletableFuture<GetObjectResponse> future = client.getObject(
        GetObjectRequest.builder()
            .bucket(BUCKET)
            .key("somedocument")
            .build(),
        AsyncResponseHandler.toFile(Paths.get("myfile.out")));
    future.whenComplete((resp, err) -> {
        try {
            if (resp != null) {
                System.out.println(resp);
            } else {
                err.printStackTrace();
            }
        } finally {
            FunctionalUtils.invokeSafely(client::close);
        }
    });
}

Notice that it is CompletableFuture<GetObjectResponse> instead of CompletableFuture<Void>.

Secondly, when this code is executed, it is returned immediately, without waiting for the task to finish.

Metadata

Metadata

Assignees

Labels

documentationThis is a problem with documentation.p3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions