title: Spring MVC Upload File from AngularJs
body: <p>i did the part AngularsJs of the file upload and when i tried to send the uploaded file to my controller i got an error that the url not valid:</p>
  
  <p>My controller is:</p>
  
  <pre><code>@RestController
  @RequestMapping("/files")
  public class UploadController {
  @RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
      @Produces(MediaType.APPLICATION_JSON) 
      public Data continueFileUpload(HttpServletRequest request, HttpServletResponse response){
              MultipartHttpServletRequest mRequest;
  
  ....
  
  }
  </code></pre>
  
  <p>the Service AngularJs that link the controller is:</p>
  
  <p>controller JS function:</p>
  
  <pre><code>$scope.uploadFile = function() {
          var file = $scope.myFile;
          console.log('file is ');
          console.dir(file);
  
          var uploadUrl = "/fileUpload";  /*i need here to know which url i must set*/
          FileUploadService.uploadFileToUrl(file, uploadUrl).then(
                  function(result) {
                      $scope.errors = FileUploadService.getResponse();
                      console.log($scope.errors);
                      $scope.errVisibility = true;
                  }, function(error) {
                      alert('error');
                  })
  
      }
  </code></pre>
  
  <p>The FileUploadService js:</p>
  
  <pre><code>myapp.service('FileUploadService', [ '$q', '$http', function($q, $http) {
      var deffered = $q.defer();
      var responseData;
      this.uploadFileToUrl = function(file, uploadUrl) {
          var fd = new FormData();
          fd.append('file', file);
          return $http.post(uploadUrl, fd, {
              transformRequest : angular.identity,
              headers : {
                  'Content-Type' : undefined
              }
          }).success(function(response) {
  
              /* $scope.errors = response.data.value; */
              console.log(response);
              responseData = response;
              deffered.resolve(response);
              return deffered.promise;
          }).error(function(error) {
              deffered.reject(error);
              return deffered.promise;
          });
  
      }
  
      this.getResponse = function() {
          return responseData;
      }
  
  } ]);
  </code></pre>
  
  <p>I wonder which URl i must pass in order to call the continueFileUpload?</p>
  
  <p>Updated:</p>
  
  <p><a href="https://i.stack.imgur.com/xBRet.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xBRet.png" alt="controller java"></a></p>
  
  <p>the itr is loaded empty</p>
  
  <p>the directive i used is :</p>
  
  <p><a href="https://i.stack.imgur.com/Z9lKE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z9lKE.png" alt="directive for file upload"></a></p>
  
  <p>the html :</p>
  
  <p><a href="https://i.stack.imgur.com/VVsWP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VVsWP.png" alt="html file upload"></a></p>