【发布时间】:2019-01-31 15:14:04
【问题描述】:
我必须上传一个带有 S3 为我创建的预签名 URL 的文件。为了节省一些空间和时间,我使用了一个将文件压缩为 .gz 格式的流。所以 S3 只接收 gz 文件。
我使用AWS S3 CPP SDK。 AWS::HttpClient 用于 HTTP 请求,boost 用于压缩。
我在问自己如何正确设置 HTTP 请求的内容长度?一方面它是一个流,另一方面流将被压缩(gz),这使得它不容易。很遗憾,我不知道该怎么做。
我尝试使用seekg() 和tellg() 获取长度,但我无法解决我的问题。
auto&& f = std::fstream{ filepath.string(), std::ios_base::in | std::ios_base::binary };
auto in = std::make_shared<boost::iostreams::filtering_stream<boost::iostreams::bidirectional>>();
in->push(boost::iostreams::combine(boost::iostreams::gzip_compressor(), boost::iostreams::gzip_decompressor()));
in->push(f);
req->AddContentBody(in);
//req->SetContentLength(); <-- How?
req->SetContentType("application/octet-stream");
auto res = MyHttpClient->MakeRequest(req); //upload stream
【问题讨论】:
标签: c++ amazon-web-services http amazon-s3 stream