Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Controlling iostreams used by the HttpClient and the AWSClient in the AWS SDK for C++

Focus mode
Controlling iostreams used by the HttpClient and the AWSClient in the AWS SDK for C++ - AWS SDK for C++

By default, all responses use an input stream backed by a stringbuf. If needed, you can override the default behavior. For example, if you are using an Amazon S3 GetObject and don’t want to load the entire file into memory, you can use IOStreamFactory in AmazonWebServiceRequest to pass a lambda to create a file stream.

Example file stream request

//! Use a custom response stream when downloading an object from an Amazon Simple //! Storage Service (Amazon S3) bucket. /*! \param bucketName: The Amazon S3 bucket name. \param objectKey: The object key. \param filePath: File path for custom response stream. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SdkCustomization::customResponseStream(const Aws::String &bucketName, const Aws::String &objectKey, const Aws::String &filePath, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::S3::S3Client s3_client(clientConfiguration); Aws::S3::Model::GetObjectRequest getObjectRequest; getObjectRequest.WithBucket(bucketName).WithKey(objectKey); getObjectRequest.SetResponseStreamFactory([filePath]() { return Aws::New<Aws::FStream>( "FStreamAllocationTag", filePath, std::ios_base::out); }); Aws::S3::Model::GetObjectOutcome getObjectOutcome = s3_client.GetObject( getObjectRequest); if (getObjectOutcome.IsSuccess()) { std::cout << "Successfully retrieved object to file " << filePath << std::endl; } else { std::cerr << "Error getting object. " << getObjectOutcome.GetError().GetMessage() << std::endl; } return getObjectOutcome.IsSuccess(); }
Note

There's more on GitHub. Find the complete example in the AWS Code Examples Repository.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.