title: How to set a content length for AWS S3 HTTP upload with presigned url for a file that is gz-compressed in std::fstream?
body: <p>I have to upload a file with a presigned URL that S3 creates for me. To save up some space and time I am using a stream that compresses the file into .gz-format. So the S3 just receives the gz-file.</p>
  
  <p>I use the <a href="https://github.com/aws/aws-sdk-cpp" rel="nofollow noreferrer">AWS S3 CPP SDK</a>. The <code>AWS::HttpClient</code> for the HTTP request and <code>boost</code> for the compression.</p>
  
  <p>I am asking myself how can I set the content length for the HTTP request correctly? On one hand it is a stream, on the other hand the stream will be compressed (gz) which makes it not easier. I have no idea how to do this, sadly.</p>
  
  <p>I tried to get the length with <code>seekg()</code> and <code>tellg()</code> but I couldn't solve my problem.</p>
  
  <pre><code>auto&amp;&amp; f = std::fstream{ filepath.string(), std::ios_base::in | std::ios_base::binary };
  
  auto in = std::make_shared&lt;boost::iostreams::filtering_stream&lt;boost::iostreams::bidirectional&gt;&gt;();
  in-&gt;push(boost::iostreams::combine(boost::iostreams::gzip_compressor(), boost::iostreams::gzip_decompressor()));
  in-&gt;push(f);
  
  req-&gt;AddContentBody(in);
  //req-&gt;SetContentLength(); &lt;-- How?
  req-&gt;SetContentType("application/octet-stream");
  
  auto res = MyHttpClient-&gt;MakeRequest(req);  //upload stream
  </code></pre>