title: ASP .Net Web API RC: Multipart file-upload to Memorystream
body: <p>I'm trying to save (an) uploaded file(s) to a database/memorystream, but I can't figure it out.</p>
  
  <p>All I have right now is this:</p>
  
  <pre><code>public Task&lt;HttpResponseMessage&gt; AnswerQuestion()
  {
      if (!Request.Content.IsMimeMultipartContent())
      {
          throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
      }
  
      var root = HttpContext.Current.Server.MapPath("~/App_Data");
      var provider = new MultipartFormDataStreamProvider(root);
  
      var task = Request.Content.ReadAsMultipartAsync(provider).
          ContinueWith&lt;HttpResponseMessage&gt;(t =&gt;
          {
              if (t.IsFaulted || t.IsCanceled)
              {
                  Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
              }
  
              foreach (var file in provider.FileData)
              {
                  Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                  Trace.WriteLine("Server file path: " + file.LocalFileName);
              }
              return Request.CreateResponse(HttpStatusCode.OK);
          });
  
      return task;
  }
  </code></pre>
  
  <p>But of course this only saves the file to a specific location. I think I have to work with a custom class derived from MediaTypeFormatter to save it to a MemoryStream, but I don't see how to do it.</p>
  
  <p>Please help. Thanks in advance!</p>