title: uploading files using angularjs and spring boot
body: <p>I have an <code>angularjs</code> application deployed in a server, and a <code>spring boot</code> application deployed in another server.</p>
  
  <p>in my angularjs application I have a form that uploads a file and send it via a rest controller, this controller then saves this file inside a folder in the server where the spring boot application is deployed.</p>
  
  <p>this is my rest controller :</p>
  
  <pre><code>@CrossOrigin(origins="*")
  @RestController
  public class Upload {
  
      @RequestMapping(value="/imageUpload", method = RequestMethod.POST)
      public void UploadFile(MultipartHttpServletRequest request) throws IOException {
  
          Iterator&lt;String&gt; itr=request.getFileNames();
          MultipartFile file=request.getFile(itr.next());
          String fileName=file.getOriginalFilename();
          File dir = new File("C:\\file");
          if (dir.isDirectory())
          {
              File serverFile = new File(dir,fileName);
              BufferedOutputStream stream = new BufferedOutputStream(
                      new FileOutputStream(serverFile));
              stream.write(file.getBytes());
              stream.close();
          }else {
              System.out.println("not");
          }
  
      }
  }
  </code></pre>
  
  <p>and this my <code>angularjs</code> controller which sends the file :</p>
  
  <pre><code>$scope.validerOffre= function(){
      var file = $scope.fileUpload;
      var uploadUrl = "/imageUpload";
      fileUploadService.uploadFileToUrl(file, uploadUrl);
      };
  </code></pre>
  
  <p>this controller then call the fileUploadService :</p>
  
  <pre><code>capValueRecruitApp.service('fileUploadService', function ($http) {
    this.uploadFileToUrl = function(file, uploadUrl){
      var fd = new FormData();
      fd.append('file', file);
      $http.post('http://localhost:8080' + uploadUrl, fd, {
          transformRequest: angular.identity,
          headers: {'Content-Type': undefined}
        })
        .success(function(){
        })
        .error(function(){
        });
    }
  });
  </code></pre>
  
  <p>and in my angularjs application I want to display the files that I uploaded but I cant do that since the files were uploaded in the spring boot application server, which is another server .</p>
  
  <p>so my question is how can I save the files that I uploaded in a folder in the angularjs application server instead of the server where the spring boot application is deployed.</p>