title: ASP.NET MVC 4 Web Api ajax file upload
body: <p>I am developing some sort of service using asp.net mvc 4 web api. On one form user must upload few files and then submit form to server. Problem is in ajax file upload to asp.net mvc web api. I have already implemented upload without ajax. But i need it's done with ajax.
  This is implementation of </p>
  
  <pre><code>public Task&lt;HttpResponseMessage&gt; PostJob()
  {
      if (!Request.Content.IsMimeMultipartContent())
      {
          throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
      }
  
      string path = HttpContext.Current.Server.MapPath(string.Format("~/Resources/Documents"));
      MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(path);
      var request = Request.Content.ReadAsMultipartAsync(provider);
  
      var task = request.ContinueWith&lt;HttpResponseMessage&gt;(t =&gt;
      {
          if (t.IsFaulted || t.IsCanceled)
          {
              return new HttpResponseMessage(HttpStatusCode.InternalServerError);
          }
  
          string fileName = provider.BodyPartFileNames.FirstOrDefault().Value;
          string originalName = provider.BodyPartFileNames.FirstOrDefault().Key.TrimStart('"').TrimEnd('"');
          string RandomName = provider.BodyPartFileNames.First().Value + Path.GetExtension(originalName);
  
          FileInfo file = new FileInfo(fileName);
          file.CopyTo(Path.Combine(path, originalName), true);
          file.Delete();
  
  
          return new HttpResponseMessage(HttpStatusCode.Created);
  
      });
  </code></pre>
  
  <p>I have found article that does this using HTML5 <a href="http://www.strathweb.com/2012/04/html5-drag-and-drop-asynchronous-multi-file-upload-with-asp-net-webapi/" rel="noreferrer">http://www.strathweb.com/2012/04/html5-drag-and-drop-asynchronous-multi-file-upload-with-asp-net-webapi/</a>. I need this work in IE8. Maybe you have any ideas?</p>
  
  <p>Any help is appreciated,
  Iryna.</p>