title: Upload file ASP.NET 5
body: <p>I'm trying to upload a file in ASP.NET 5 but the two ways I've seen on internet fail.
  With XMLHttpRequest here is my server side code:</p>
  
  <pre><code> public async Task&lt;ActionResult&gt; UploadSWF()
   {
       StreamReader reader = new StreamReader(Request.Body);
       var text = await reader.ReadToEndAsync();
       return View();
   }
  </code></pre>
  
  <p><strong>[EDIT 1]</strong>: And my client side:</p>
  
  <pre><code>var client = new XMLHttpRequest();
  function upload() 
  {
     var file = document.getElementById("uploadfile");
     var formData = new FormData();
     formData.append("upload", file.files[0]);
     client.open("post", "/Home/UploadSWF", true);
     //client.setRequestHeader("Content-Type", "multipart/form-data");
     client.setRequestHeader("Content-Type", "application/x-shockwave-flash");
     client.send(formData);
  }
  </code></pre>
  
  <p>But the only thing I can get from this is:</p>
  
  <blockquote>
    <p>------WebKitFormBoundaryX1h5stVbtaNe6nFw
    Content-Disposition: form-data; name="upload"; filename="data.swf"
    Content-Type: application/x-shockwave-flash
    CWS
    ;"</p>
  </blockquote>
  
  <p><strong>[EDIT 2]</strong>:Here is the code how I get this:</p>
  
  <pre><code> public ActionResult UploadSWF()
      {
          Stream bodyStream = Context.Request.Body;
          var sr = new StreamReader(bodyStream);
          var test = sr.ReadToEnd();
          return View();
      }
  </code></pre>
  
  <p>So I get the name of the file and the content-type but not its content. </p>
  
  <p>This answer <a href="https://stackoverflow.com/a/26445416/1203116">https://stackoverflow.com/a/26445416/1203116</a> is copying the stream into a file however the file creation part isn't working for me, I don't know what's going on but nothing happens. So I tried to do the same with a MemoryStream and I got an empty string.</p>
  
  <p>So finally I tried another way, using IFormFile like shown here: <a href="https://github.com/aspnet/Mvc/blob/437eb93bdec0d9238d672711ebd7bd3097b6537d/test/WebSites/ModelBindingWebSite/Controllers/FileUploadController.cs" rel="nofollow noreferrer">https://github.com/aspnet/Mvc/blob/437eb93bdec0d9238d672711ebd7bd3097b6537d/test/WebSites/ModelBindingWebSite/Controllers/FileUploadController.cs</a> 
  This interface should be in Microsoft.AspNet.Http which I've added to my project but I'm still not able to access it. I can't see any IFormFile in this namespace.</p>
  
  <p><strong>[EDIT 1]</strong>: The first method I've tried is by using HttpPostedFileBase like I was used to in ASP.NET MVC 5 but it was not working in my vNext project. I always got an MissingMethodException.
  My code on client side was:</p>
  
  <pre><code>&lt;form action="/home/UploadSWF" method="POST" enctype="multipart/form-data"&gt;
          &lt;input type="file" name="file" accept=".swf, application/x-shockwave-flash/*"&gt;
          &lt;input type="submit" name="submit" /&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>And in my controller:</p>
  
  <pre><code>public ActionResult UploadSWF(HttpPostedFileBase file)
  {
       return View();
  }
  </code></pre>