title: HttpClient: How to upload multiple files at once
body: <p>I am trying to upload muliple files using <a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx">System.Net.Http.HttpClient</a>.</p>
  
  <pre><code>using (var content = new MultipartFormDataContent())
  {
     content.Add(new StreamContent(imageStream), "image", "image.jpg");
     content.Add(new StreamContent(signatureStream), "signature", "image.jpg.sig");
  
     var response = await httpClient.PostAsync(_profileImageUploadUri, content);
     response.EnsureSuccessStatusCode();
  }
  </code></pre>
  
  <p>this only sends mulipart/form-data, but i expected multipart/mixed somewhere in the post.</p>
  
  <p>UPDATE: Ok, i got around.</p>
  
  <pre><code>using (var content = new MultipartFormDataContent())
  {
      var mixed = new MultipartContent("mixed")
      {
          CreateFileContent(imageStream, "image.jpg", "image/jpeg"),
          CreateFileContent(signatureStream, "image.jpg.sig", "application/octet-stream")
      };
  
      content.Add(mixed, "files");
  
      var response = await httpClient.PostAsync(_profileImageUploadUri, content);
      response.EnsureSuccessStatusCode();
  }
  
  private StreamContent CreateFileContent(Stream stream, string fileName, string contentType)
  {
      var fileContent = new StreamContent(stream);
      fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("file") {FileName = fileName};
      fileContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
      return fileContent;
  }
  </code></pre>
  
  <p>This looks correct on wire shark. but i do not see the files in my controller.</p>
  
  <pre><code>[HttpPost]
  public ActionResult UploadProfileImage(IEnumerable&lt;HttpPostedFileBase&gt; postedFiles)
  {
      if(postedFiles == null)
          return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  
      // more code here
  }
  </code></pre>
  
  <p><code>postedFiles</code> is still null. Any ideas?</p>