title: File upload in angularjs mvc
body: <p>Please see the following code and let me know how can i upload the file in a folder of my project..
  where can i write the url? I select the file and it does not get save simply by clicking on the update button.</p>
  
  <p>Thanks in Advance
  Ria</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var DocTrack = angular.module('DocTrack', []);
  
  DocTrack.controller('DocumentController', DocumentController);
  
  DocTrack.directive('fileModel', ['$parse', function ($parse) {
      return {
          
          restrict: 'A',
          link: function (scope, element, attrs) {
              var model = $parse(attrs.fileModel);
              var modelSetter = model.assign;
  
              element.bind('change', function () {
                  scope.$apply(function () {
                      modelSetter(scope, element[0].files[0]);
                  });
              });
          }
      };
  }]);
  
  DocTrack.service('fileUpload', ['$http', function ($http) {
      debugger;
      this.uploadFileToUrl = function (file, uploadUrl) {
          var fd = new FormData();
          fd.append('file', file);
          $http.post(uploadUrl, fd, {
              transformRequest: angular.identity,
              headers: { 'Content-Type': undefined }
          })
          .success(function () {
              alert('File Uploaded Successfully...');
          })
          .error(function () {
              alert('File has not been uploaded');
          });
      }
  }]);
  
  DocTrack.controller('DocumentController', ['$scope', 'fileUpload', function ($scope, fileUpload) {
  
      $scope.uploadFile = function () {
           debugger;
          var file = $scope.myFile;
          console.log('file is ' + JSON.stringify(file));
      
          var uploadUrl = "http://localhost:40966/fileUpload";
          fileUpload.uploadFileToUrl(file, uploadUrl);
      };
  }]);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>      &lt;div ng-controller = "DocumentController"&gt;
             &lt;input type="file" file-model="myFile" /&gt;          
             &lt;button ng-click="uploadFile()" data-url=""&gt;upload me&lt;/button&gt;            
          &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>