title: Custom form data with multiple files to Web API controller
body: <p>I have problems of getting all the form data I've specified in my API Controller.</p>
  <p><strong>javascript upload function:</strong></p>
  <pre><code>$scope.upload[index] = $upload.upload({
          url: '/api/upload/',
          method: 'POST',
          data: {
              Photographer: $scope.models[index].photographer,
              Description: $scope.models[index].desc
          },
          file: $scope.models[index].file
      })
  </code></pre>
  <p><strong>Form data:</strong>
  Works as I want it to, for each request that is sent it includes my values as i want it to.</p>
  <pre><code>------WebKitFormBoundaryzlLjAnm449nw1EvC
  Content-Disposition: form-data; name=&quot;Photographer&quot;
  
  Scott Johnson
  ------WebKitFormBoundaryzlLjAnm449nw1EvC
  Content-Disposition: form-data; name=&quot;Description&quot;
  
  Image taken with a Nikon camerea
  ------WebKitFormBoundaryzlLjAnm449nw1EvC
  Content-Disposition: form-data; name=&quot;file&quot;; filename=&quot;moxnes.jpg&quot;
  Content-Type: image/jpeg
  </code></pre>
  <p><strong>My Web API Controller:</strong></p>
  <p>Template from <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2" rel="nofollow noreferrer">this guide</a></p>
  <pre><code>public class UploadController : ApiController
  {
      public async Task &lt; HttpResponseMessage &gt; PostFormData() 
      {
          var root = HttpContext.Current.Server.MapPath(&quot;~/App_Data&quot;);
          var provider = new MultipartFormDataStreamProvider(root);
  
          try 
          {
              // Read the form data.
              await Request.Content.ReadAsMultipartAsync(provider);
  
              // Show all the key-value pairs.
              foreach(var key in provider.FormData.AllKeys) 
              {
                  foreach(var val in provider.FormData.GetValues(key)) 
                  {
                      var keyValue = string.Format(&quot;{0}: {1}&quot;, key, val);
                  }
              }
  
              foreach(MultipartFileData fileData in provider.FileData) 
              {
                  var fileName = fileData.Headers.ContentDisposition.FileName;
              }
              return Request.CreateResponse(HttpStatusCode.OK);
          } 
          catch (Exception e) 
          {
              return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
          }
      }
  }
  </code></pre>
  <p>Here's the problem: The controller can receive multiple request asynchronously and read all the files through this loop:  <code>foreach(MultipartFileData fileData in provider.FileData)</code> which works fine, but my other form data values (Phtographer and Description) does only include values from one of the requests (the last request received).</p>
  <pre><code>foreach(var key in provider.FormData.AllKeys)
  </code></pre>
  <p>I need to take out each requests form data values. How can I do it, or is there any better way of solving this? Maybe by adding a model as parameter?</p>