title: 415 Unsupported Media Type Using JQuery/FormData and Web Api
body: <p>I'm getting a Error :</p>
  
  <pre><code>"POST {URL} 415 (Unsupported Media Type)" error 
  </code></pre>
  
  <p>And cannot figure out why it's happening.</p>
  
  <p>I'm trying to upload an excel file in <strong><code>JQuery using FormData.</code></strong></p>
  
  <p>Here is the <strong>code:</strong></p>
  
  <pre><code>var formdata = new FormData();
  var file = input.get(0).files[0];
  formdata.append('content', file);
  
  var url = "/Phrase/Import/" + $('.exportPanel #Language').val()
  
  var ajax = $.ajax({
      url: url,
      type: "POST",
      data: formdata,
      processData: false,
      contentType: false,
      success: function (data, textStatus, jqXHR) {
          //Do something.
      },
      error: function (jqXHR, textStatus, errorThrown) {
          //Do something.
      }
  });
  </code></pre>
  
  <p>Here is the controller code:</p>
  
  <pre><code>[Route("Import/{languageID}")]
  [HttpPost]
  public void ImportPhrases([FromUri]int languageID, [FromBody]Stream content)
  {
      _service.ImportPhrases(content, languageID);          
  }
  </code></pre>
  
  <p>I noticed that, according to Fiddler, the content type of the request is different to that of the response (not sure if this makes a difference?).</p>
  
  <pre><code>Request: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  Response: application/json; charset=utf-8
  </code></pre>
  
  <p>The JQuery above is being used in a different part of the system, but uses WCF instead of Web API (am in the process of changing from WCF to MVC/Web API), again I'm not sure if this makes a difference?</p>
  
  <p>Can anyone tell me what I'm doing wrong please?</p>
  
  <p>Many thanks.</p>