title: How do I get the file contents of a MultipartMemoryStreamProvider as a byte array?
body: <p>I have created a component that uploads files to a Web API controller using FormData.</p>
  
  <p>How do I get the file contents from the MultipartMemoryStreamProvider as a byte array?</p>
  
  <p><strong>Here is the Web Api method</strong></p>
  
  <pre><code>   public Task&lt;IEnumerable&lt;FileModel&gt;&gt; Post()
     {             
       if (Request.Content.IsMimeMultipartContent())
          {            
              var streamProvider = new MultipartMemoryStreamProvider();
              var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith&lt;IEnumerable&lt;FileModel&gt;&gt;(t =&gt;
              {
  
                  if (t.IsFaulted || t.IsCanceled)
                  {
                      throw new HttpResponseException(HttpStatusCode.InternalServerError);
                  }
  
                  FileDataBO filedata;
                  var fileInfo = streamProvider.Contents.Select(i =&gt; {
                      //save to db
                      filedata = new FileDataBO ();
                      filedata.FileName = i.Headers.ContentDisposition.FileName;
                      filedata.FileType = "jpeg";
  
                      // HOW TO GET FILE CONTENT HERE??? IT SHOULD BYTE[]
                      //filedata.FileContent = ???
  
                      //TODO
                      //_fileDataService.SaveFile(filedata);    
  
                      return new FileModel(i.Headers.ContentDisposition.FileName, 2048);
                  });
                  return fileInfo;
              });
  
              return task;
          }             
          else
          {
              throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
          }       
     }
  </code></pre>