title: Reading FormData from HttpContext in .Net Core 2.0
body: <p>In Core 2.0, trying to read in my FormData posted from front end. I can manage to read the array of JSON objects, but not the <code>Files[]</code> array I'm also posting in the Form Data.</p>
  
  <p>Here's the <code>Angular</code> component code which builds <code>FormData</code> :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const formData = new FormData();
  formData.append("MediaInfo",  JSON.stringify(minfo));
   
  for(var i=0; i&lt;this.importImages.length; i++){
      // append images to the files[] array
      formData.append("files[]", this.dataURItoBlob(this.importImages[i].TnUrl), this.importImages[i].name);
     }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And I call the following <code>Angular</code> service:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> saveImportObjects(formData: FormData, params){
    let headers = new Headers();
    let options = new RequestOptions({ headers: headers });
    options.params = params;
  
    var url = this.host + 'import/MediaUpload?' + this.getSessionID();
  
    return this.http.post(url, formData, options)
            .map((result: any) =&gt; {
              let res = result._body;
            })
            .catch(this.handleError);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The Web Api code :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[HttpPost]
  [Route("MediaUpload")]
  [DisableFormValueModelBindingAttribute]
  public async Task&lt;HttpResponseMessage&gt; MediaUploadAsync(string patientId, [FromQuery]string sessionId)
  {
  
   FormOptions _defaultFormOptions = new FormOptions();
  
   if (!Helpers.MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
   {
    throw new GetDataException("Unsupported Media Type");
   }
  
   var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);            
   var reader = new MultipartReader(boundary, HttpContext.Request.Body);
   var section = await reader.ReadNextSectionAsync();
   
   StreamReader stream = new StreamReader(section.Body, Encoding.UTF8);
   var data = stream.ReadToEndAsync();
  
    List&lt;MediaInfo&gt; listMedia = new List&lt;MediaInfo&gt;();
   
   HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.Accepted);
   return msg;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The good news is that my <code>data</code> object is showing the array of objects (one object in this case); however, I'm not getting to my <code>Files[]</code> array:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[{"PatientID":2,"PatientLastName":"Comprehensive","PatientFirstName":"Connie","DeviceID":"46","CSIInstanceID":9,"PatientDOB":"1958-09-09","FileName":"eye2.jpg","FileSize":5880,"ExamDate":"1/29/2018","PatientUID":2,"SessionID":"sessionID=4e92cdc3-3cba-4c96-86fa-d8049d9ea968"}]</code></pre>
  </div>
  </div>
  </p>
  
  <p>Captured request in <code>Fiddler</code> tool:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>POST /api/import/MediaUpload?sessionID=cfe351c8-63f8-40b0-909d-d9a5991f6a70&amp;patientID=11 HTTP/1.1
  
  POST /api/import/MediaUpload?sessionID=cfe351c8-63f8-40b0-909d-d9a5991f6a70&amp;patientID=11 HTTP/1.1
  Host: localhost:49491
  Connection: keep-alive
  Content-Length: 399616
  Accept: application/json, text/plain, */*
  Origin: http://localhost:4200
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundary62hryFjhCKbptVPz
  Referer: http://localhost:4200/
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9</code></pre>
  </div>
  </div>
  </p>
  
  <p>Same request via <code>Fiddler</code>, in the <code>TextView</code> of request:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>------WebKitFormBoundary62hryFjhCKbptVPz
  Content-Disposition: form-data; name="MediaInfo"
  
  [{"ID":11,"LastName":"Mazzo","FirstName":"Bob","DeviceID":"46","InstanceID":9,"PatientDOB":"1967-05-01","FileName":"Bob and Chris Cardillo.jpg","FileSize":399030,"ExamDate":"1/31/2018","UID":11,"SessionID":"sessionID=cfe351c8-63f8-40b0-909d-d9a5991f6a70"}]
  ------WebKitFormBoundary62hryFjhCKbptVPz
  Content-Disposition: form-data; name="files[]"; filename="Bob and Chris Cardillo.jpg"
  Content-Type: image/jpeg
  
      </code></pre>
  </div>
  </div>
  </p>