title: C#: HttpClient, File upload progress when uploading multiple file as MultipartFormDataContent
body: <p>I'm using this code to upload multiple files and it working very well. It uses modernhttpclient library.</p>
  
  <pre><code>public async Task&lt;string&gt; PostImages (int platform, string url, List&lt;byte []&gt; imageList)
  {
      try {
          int count = 1;
          var requestContent = new MultipartFormDataContent ();
  
          foreach (var image in imageList) {
              var imageContent = new ByteArrayContent (image);
              imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse ("image/jpeg");
              requestContent.Add (imageContent, "image" + count, "image.jpg");
              count++;
          }
          var cookieHandler = new NativeCookieHandler ();
          var messageHandler = new NativeMessageHandler (false, false, cookieHandler);
          cookieHandler.SetCookies (cookies);
          using (var client = new HttpClient (messageHandler)) {
              client.DefaultRequestHeaders.TryAddWithoutValidation ("User-Agent", GetUserAgent (platform));
              using (var r = await client.PostAsync (url, requestContent)) {
                  string result = await r.Content.ReadAsStringAsync ();
                  System.Diagnostics.Debug.WriteLine ("PostAsync: " + result);
                  return result;
              }
          }
      } catch (Exception e) {
          System.Diagnostics.Debug.WriteLine (e.Message);
          return null;
      }
  }
  </code></pre>
  
  <p>Now I need the progress when uploading the files. I searched in google and found I need to use ProgressStreamContent</p>
  
  <p><a href="https://github.com/paulcbetts/ModernHttpClient/issues/80" rel="noreferrer">https://github.com/paulcbetts/ModernHttpClient/issues/80</a></p>
  
  <p>Since ProgressStreamContent contains a constructor that takes a stream, I converted the MultipartFormDataContent to stream and used it in its constructor. But, its not working. Upload fails. I think its because it is a stream of all the files together which is not what my back end is expecting.</p>
  
  <pre><code>public async Task&lt;string&gt; PostImages (int platform, string url, List&lt;byte []&gt; imageList)
  {
      try {
          int count = 1;
          var requestContent = new MultipartFormDataContent ();
              //    here you can specify boundary if you need---^
          foreach (var image in imageList) {
              var imageContent = new ByteArrayContent (image);
              imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse ("image/jpeg");
              requestContent.Add (imageContent, "image" + count, "image.jpg");
              count++;
          }
          var cookieHandler = new NativeCookieHandler ();
          var messageHandler = new NativeMessageHandler (false, false, cookieHandler);
          cookieHandler.SetCookies (RestApiPaths.cookies);
  
  
          var stream = await requestContent.ReadAsStreamAsync ();
  
          var client = new HttpClient (messageHandler);
          client.DefaultRequestHeaders.TryAddWithoutValidation ("User-Agent", RestApiPaths.GetUserAgent (platform));
  
          var request = new HttpRequestMessage (HttpMethod.Post, url);
  
          var progressContent = new ProgressStreamContent (stream, 4096);
          progressContent.Progress = (bytes, totalBytes, totalBytesExpected) =&gt; {
              Console.WriteLine ("Uploading {0}/{1}", totalBytes, totalBytesExpected);
          };
  
          request.Content = progressContent;
  
          var response = await client.SendAsync (request);
          string result = await response.Content.ReadAsStringAsync ();
  
          System.Diagnostics.Debug.WriteLine ("PostAsync: " + result);
  
          return result;
  
      } catch (Exception e) {
          System.Diagnostics.Debug.WriteLine (e.Message);
          return null;
      }
  }
  </code></pre>
  
  <p>What should I do here to get this working? Any help is appreciated</p>