

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 控制`HttpClient`和中使用的 iostrea `AWSClient` m 适用于 C\$1\$1 的 AWS SDK
<a name="configuring-iostreams"></a>

默认情况下，所有响应都使用由 `stringbuf` 支持的输入流。如果需要，可以覆盖默认行为。例如，如果您使用的是 Amazon S3 `GetObject`，并且不想将整个文件加载到内存中，则可以通过在 `AmazonWebServiceRequest` 中使用 `IOStreamFactory` 传递 lambda 来创建文件流。

 **文件流请求示例** 

```
 //! 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();
}
```

**注意**  
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/cpp/example_code/sdk-customization#code-examples)中查找完整示例。