title: How to display upload progress using C# HttpClient PostAsync
body: <p>A am creating a file upload app for Android and iOS using Xamarin PCL and i have managed to implement file upload and some sort of progress bar, but it is not working properly. </p>
  
  <p>I saw some answers on stack overflow for displaying download progress, but i want to notify my users about <strong>upload</strong> progress and did not find any solution.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static async Task&lt;string&gt; PostFileAsync (Stream filestream, string filename, int filesize) {
          var progress = new System.Net.Http.Handlers.ProgressMessageHandler ();
  
          //Progress tracking
          progress.HttpSendProgress += (object sender, System.Net.Http.Handlers.HttpProgressEventArgs e) =&gt; {
              int progressPercentage = (int)(e.BytesTransferred*100/filesize);
              //Raise an event that is used to update the UI
              UploadProgressMade(sender, new System.Net.Http.Handlers.HttpProgressEventArgs(progressPercentage, null, e.BytesTransferred, null));
          };
  
          using (var client = HttpClientFactory.Create(progress)) {
              using (var content = new MultipartFormDataContent ("------" + DateTime.Now.Ticks.ToString ("x"))) {
                  content.Add (new StreamContent (filestream), "Filedata", filename);
                  using (var message = await client.PostAsync ("http://MyUrl.example", content)) {
                      var result = await message.Content.ReadAsStringAsync ();
                      System.Diagnostics.Debug.WriteLine ("Upload done");
                      return result;
                  }
              }
          }
      }
  </code></pre>
  
  <p>Some sort of progress is displayed, but when the progress reaches 100%, the file is not uploaded yet. Message "Upload done" is also printed some time after i have received the last progress message.</p>
  
  <p>Maybe the progress is displaying bytes sent out of the device and not already uploaded bytes, so when it says, that it is 100%, all of the bytes are just sent out but not yet received by the server?</p>
  
  <p><strong>Edit:</strong> Tried this solution: <a href="https://forums.xamarin.com/discussion/56716/plans-to-add-webclient-to-pcl" rel="noreferrer">https://forums.xamarin.com/discussion/56716/plans-to-add-webclient-to-pcl</a> and it works a bit better.</p>