title: Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'. Parameter name: content
body: <p>I am getting this error:</p>
  
  <blockquote>
    <p>Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'. Parameter name: content</p>
  </blockquote>
  
  <p>when I am trying to upload file through angularjs using FormData().
  I don't know what I am doing wrong.</p>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data" ng-model="myform"&gt;
        &lt;input type="file" file-model="file1" name="file" /&gt; Upload file
        &lt;div style="margin-bottom: 12%; margin-top: 5%;"&gt;
          &lt;div style="float: right;"&gt;
            &lt;button class="btn btn-primary" ng-click="CreatePDF()"&gt;Save&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Angularjs code</p>
  
  <pre><code>$scope.CreatePDF = function () {
  
          var file = document.getElementsByName("file");
          var formData1 = new FormData();
  
          formData1.append('file', file[0].files[0], 'test.pdf');
  
          API_immigration.converttoBytes.filesBytes(formData1).then(function (res) {
            alert('hi uploaded');
          });
  }
  </code></pre>
  
  <p>This is my service file calling API from angularjs</p>
  
  <pre><code>var converttoBytes = {
      filesBytes: function (p) {
  
        return $ajax.post('/api/immigration/application/getFileObj/dddd', p, {
          contentType: 'multipart / form - data'
         }
        );
      }
  </code></pre>
  
  <p>Here is my API written in asp.net:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  [Route("getFileObj/{path}")]
  
  public async Task&lt;string&gt; postuploadfile()
  {
      var ctx = HttpContext.Current;
      var root = ctx.Server.MapPath("~/App_Data");
      var provider = new System.Net.Http.MultipartFormDataStreamProvider(root);
  
      try
      {
          // Read the form data.
          await Request.Content.ReadAsMultipartAsync(provider);
  
          // This illustrates how to get the file names.
          foreach (var file in provider.FileData)
          {
              var name = file.Headers.ContentDisposition.FileName;
              name = name.Trim('"');
              var localFileName = file.LocalFileName;
              var filepath = Path.Combine(root, name);
              File.Move(localFileName, filepath);
          }
      }
      catch (System.Exception e)
      {
      }
      return "Fileuploaded";
  }
  </code></pre>
  
  <hr>
  
  <p>I have used $http service ,but still i am getting same error, here is my raw data from filddler. </p>
  
  <pre><code>POST /api/immigration/applicationtemplate/getFileObj/dddd HTTP/1.1
  Host: localhost:31002
  Connection: keep-alive 
  Content-Length: 120145 
  Content-Type: multipart / form - data 
  Pragma: no-cache 
  Cache-Control: no-cache Accept: / 
  Origin: localhost:9002 
  Authorization: bearer earer pJhzAZ1D_tnFCY 
  Accept-Encoding: gzip, deflate, br 
  Accept-Language: en-US,en;q=0.9 –
  </code></pre>