title: Getting 400 Bad request error while uploading file using angularjs
body: <p>i'm new to angular ,i try to upload file but i got bad request error 
  i try all online examples but i get only bad request error.
  i display my code below</p>
  
  <p>This my client side part</p>
  
  <pre><code>&lt;div ng-controller = "myCtrl"&gt;
      &lt;input type="file" file-model="myFile"/&gt;
      &lt;button ng-click="uploadFile()"&gt;upload me&lt;/button&gt;
  &lt;/div&gt;
  
  
  
  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(){
          });
      }
  }]);
  
  myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
  
      $scope.uploadFile = function(){
          var file = $scope.myFile;
          console.log('file is ' + JSON.stringify(file));
          var uploadUrl = "/customers/17/artifacts";
          fileUpload.uploadFileToUrl(file, uploadUrl);
      };
  
  }]);
  </code></pre>
  
  <p>This my server side part</p>
  
  <p>controller part</p>
  
  <pre><code>@RequestMapping(value = "/customers/{accountNumber}/artifacts", method = RequestMethod.POST)
      void uploadCustomerArtifact(@PathVariable Long accountNumber, @RequestParam("artifact") MultipartFile uploadfile, HttpServletRequest request, HttpServletResponse response) {
          log.info("RestController UploadFile Called");
  
          artifactService.uploadArtifacts(accountNumber, uploadfile, request, response);
      }
  </code></pre>
  
  <p>service part</p>
  
  <pre><code>@Transactional
      void uploadArtifacts(Long accountNumber, MultipartFile uploadfile, HttpServletRequest request, HttpServletResponse response)
      {
          BufferedOutputStream stream
          try {
  
              Validate.assertNotNull(accountNumber,"field.required","Customer account number is mandatory");
  
              Customer existingCustomer = customerRepository.findByAccountNumber(accountNumber);
              Validate.assertNotNull(existingCustomer, "not.exist", "Customer account number doesn't exist");
  
              Artifact myArtiFact = new Artifact();
              myArtiFact.name = uploadfile.getOriginalFilename();
              myArtiFact.type = uploadfile.getContentType();
              myArtiFact.content = uploadfile.bytes
  
              String contentType = request.getServletContext().getMimeType(FilenameUtils.getName(uploadfile.getOriginalFilename()));
  
              println "contentType : "+contentType
  
              existingCustomer.addArtifact(myArtiFact);
  
              customerRepository.save(existingCustomer);
              log.info("UploadArtifacts Success");
  
          }
          catch (Exception e) {
              throw e;
          }
          finally
          {
              if(stream != null)
              {
                  stream.close();
              }
          }       
      }
  </code></pre>