title: Image upload using rest api in Angularjs
body: <p>I have to upload image using rest api for successfull upload will get the response of file folder destination ex: <code>D:/ddd/download</code>,I am not able to upload image, below is my code given suggest me any corrections. while uploading image i have to give parameter name as fileData.
  api ex: <a href="http://somelink" rel="nofollow">http://somelink</a>  and parameter for post is fileData</p>
  
  <p><strong>Html code</strong></p>
  
  <pre><code>&lt;input type = "file" file-model = "myFile"/&gt;
  &lt;button ng-click = "uploadFile()"&gt;upload me&lt;/button&gt;
  </code></pre>
  
  <p><strong>my service and directive</strong></p>
  
  <pre><code> myApp.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]);
                   });
                });
             }
          };
       }]);
  
       myApp.service('fileUpload', ['$http', function ($http) {
          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(){
             })
  
             .error(function(){
             });
          }
       }]);
  </code></pre>
  
  <p><strong>my controller file</strong></p>
  
  <pre><code> $scope.uploadFile = function(){
                  var data={
              'fileData':$scope.myFile
      }
      var uploadUrl = "http://";
      fileUpload.uploadFileToUrl(data, uploadUrl).success(function(response) {
          $scope.fileName=response;
      })
     };
  </code></pre>