如何使用前缀 url 和 Aws::FStream 将文件上传到 AWS S3?

How to upload file to AWS S3 with presigend url and Aws::FStream?

我想将文件从我的系统上传到 AWS S3 服务器。我正在使用允许我上传文件的预签名 url。

它必须在流中发生,因为我们希望将来在上传过程中对文件进行 gzip 压缩。我尝试使用 HttpClientFactory 并能够使用流下载文件。

遗憾的是我在上传过程中卡住了。我不确定如何使用能够从我的系统读取文件的流来填充请求。

我试图用 StreamFactory 填充请求,但无法用我的 Aws::FStream.

初始化一个
auto url = client->GeneratePresignedUrl("bucketName", "s3Key", Aws::Http::HttpMethod::HTTP_POST, 3600);

static std::shared_ptr<Aws::Http::HttpClientFactory> MyClientFactory{};
auto MyHttpClient = Aws::Http::CreateHttpClient(getClientConfig());

const std::shared_ptr<Aws::Http::HttpRequest> req(
    Aws::Http::CreateHttpRequest(url, Aws::Http::HttpMethod::HTTP_POST,
        Aws::Utils::Stream::DefaultResponseStreamFactoryMethod));

std::shared_ptr<Aws::IOStreamFactory> streamfac;
Aws::New<Aws::FStream>("C:/Development/test3.txt", std::ios_base::in);

std::shared_ptr<Aws::IOStreamFactory>
//Stuck here: req->SetResponseStreamFactory(???)

我能够解决问题。

auto inStream = std::make_shared<boost::filesystem::fstream>(filepath, std::ios_base::in | std::ios_base::binary);

req->AddContentBody(inStream);

auto res = MyHttpClient->MakeRequest(req);