title: How to upload a file using angular JS and send it to C# web API?
body: <p>I wanted to upload a file (maybe <code>.csv</code>, <code>.txt</code>, <code>.xls</code>, etc.) which contains some text, and I want the document to be processed by C#. I use Angular JS in my front end and C# for WebAPI.</p>
  
  <p>I need help how to upload the file to C#?</p>
  
  <p>I tried:</p>
  
  <p>in C# WebAPI controller:</p>
  
  <pre><code>    [HttpPost]
      [Route("api/GetCalimCsv")]
      public string GetCalimCsv(dynamic content)
      {
          return content;
      }
  </code></pre>
  
  <p>It's getting the null value.</p>
  
  <p>In angular controller:</p>
  
  <pre><code>$scope.fileNameChanged = function (ele) {
      var formData = new FormData();
      formData.append('claim', ele.files[0]);
      $http({
          method: 'POST',
          url: '/api/GetCalimCsv/',
          data: formData
          }).then(function successCallback(response) {
          alertify.success(response.data);
      }, function errorCallback(response) {
          alertify.error(response.status);
      });
  </code></pre>
  
  <p>In CSHTML file:</p>
  
  <pre><code>&lt;input ng-model="Claim" ng-required="true"
      type="file" accept=".js, .css, .txt, .doc, .docx, .csv, .xls | text/*"
      onchange="angular.element(this).scope().fileNameChanged(this)" /&gt;
  </code></pre>
  
  <p>sample screenshot during file input:
  <a href="https://i.stack.imgur.com/Kwe3z.png" rel="nofollow noreferrer">JavaScript is getting the file name</a></p>