Controlar iostreams usados pelo HttpClient e pelo AWSClient no AWS SDK para C++
Por padrão, todas as respostas usam um fluxo de entrada apoiado por um stringbuf. Se necessário, você poderá substituir o comportamento padrão. Por exemplo, se você estiver usando um GetObject do Amazon S3 e não quiser carregar o arquivo inteiro na memória, poderá usar IOStreamFactory em AmazonWebServiceRequest para transmitir um lambda a fim de criar um fluxo de arquivos.
Exemplo de solicitação de fluxo de arquivos
//! 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(); }
nota
Há mais no GitHub. Encontre o exemplo completo no Repositório de exemplos de código da AWS