Skip to content

Object data is not accessible inside Aws::S3::GetObjectResponseReceivedHandler() #918

Closed
@dzjiang91

Description

@dzjiang91

Trying to use Aws::S3::S3Client::GetObjectAsync and handle the object data in the callback.

virtual void GetObjectAsync(const Model::GetObjectRequest& request, const GetObjectResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr) const;

typedef std::function<void(const S3Client*, const Model::GetObjectRequest&, const Model::GetObjectOutcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&) > GetObjectResponseReceivedHandler;

Similar to use of GetObject() in https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/examples-s3-objects.html,
here is what I tried to do:

Aws::S3::GetObjectResponseReceivedHandler callback = [](
    const S3Client*,
    const Model::GetObjectRequest& request,
    const Model::GetObjectOutcome& outcome,
    const std::shared_ptr<const Aws::Client::AsyncCallerContext>&){
     Aws::IOStream& body = outcome.GetResult().GetBody();
     <other operations on body>
}

This does NOT work because outcome is passed as const reference and Aws::S3::Model::GetObjectResult::GetBody() is not a const accessor.

    /**
     * <p>Object data.</p>
     */
    inline Aws::IOStream& GetBody() { return m_body.GetUnderlyingStream(); }

So how should we access s3 object data in callback of GetObjectAsync? Is there any workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions