title: Upload file with progress using PUT request in PCL
body: <p>How to implement put request with progress in .NET PCL? How to disable write stream buffering?
  I'm trying to implement put file logic with progress in PCL, but can't seem find the right way to do that. The underlying trasport level buffers the stream and my progress got stuck during get response. So, it reports quickly during copying to internal buffer, then got stuck during put request.
  AllowWriteStreamBuffering is not available in PCL, so I was unable to get progress from HttpWebRequest. As for now I'm using the following approach, which doesn't work correctly as well:</p>
  
  <pre><code>using (HttpClient client = new HttpClient())
  {   
      client.DefaultRequestHeaders.TransferEncodingChunked = true;            
      ChunkedContent chunkedContent = new ChunkedContent(content, cancellationToken, true, progressInBytes);
      var response = await client.PutAsync(uri, chunkedContent, cancellationToken);
      return await response.Content.ReadAsStreamAsync();
  }
  
  
  public class ChunkedContent : HttpContent
  {
      public ChunkedContent(Stream inputStream,CancellationToken token, bool canReportProgress, Action&lt;double&gt; notifyProgressInBytes = null)
      {
          _canReportProgress = canReportProgress;
          _inputStream = inputStream;
          _token = token;
          _notifyProgressInBytes = notifyProgressInBytes;
      }
      private Action&lt;double&gt; _notifyProgressInBytes;
      private bool _canReportProgress;
      private CancellationToken _token;
      const int BufferSize = 4096;        
      private Stream _inputStream;
      protected override async Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext context)
      {
  
          var totalRead = 0L;
          var buffer = new byte[BufferSize];
          var isMoreToRead = true;
  
          do
          {
              _token.ThrowIfCancellationRequested();
  
              var read = await _inputStream.ReadAsync(buffer, 0, buffer.Length, _token);
  
              if (read == 0)
              {
                  isMoreToRead = false;
              }
              else
              {
                  var data = new byte[read];
                  await stream.WriteAsync(buffer, 0, read);                   
  
                  totalRead += read;
  
                  if (_canReportProgress &amp;&amp; _notifyProgressInBytes != null)
                  {
                      _notifyProgressInBytes(totalRead);
                      System.Diagnostics.Debug.WriteLine(totalRead);
                  }
              }
          } while (isMoreToRead);
  
      }
      protected override bool TryComputeLength(out long length)
      {
          length = _inputStream.Length;
          return true;
      }
  }
  </code></pre>