title: How to set request part for POST request with angular-file-upload and Spring?
body: <p>Unfortunately <a href="https://stackoverflow.com/questions/42031959/how-to-correctly-attach-file-to-formdata-before-posting-to-server">this answer</a> does not help me. The problem appears to be that the request parameter <code>file</code> is not present in my POST request for some reason.</p>
  
  <p>I am trying to upload a file, any file whether it's a binary file or a text file, in a POST request. The REST controller reveals:</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping(WordEmbeddingApiPaths.UPLOAD_MODEL)
  @RequestMapping(method=RequestMethod.POST, headers={"Content-Type=multipart/form-data"})
  public ResponseEntity&lt;WordVectorListDto&gt; uploadModel(
          @RequestParam("file") MultipartFile file, 
          RedirectAttributes redirectAttributes) {
  
      LOGGER.debug("POST uploadModel");
  
      return new ResponseEntity&lt;WordVectorListDto&gt;((WordVectorListDto)null, HttpStatus.OK); 
  }
  </code></pre>
  
  <p>and on the client I am running:</p>
  
  <pre><code>var uploader = $scope.uploader = new FileUploader({
      url: 'http://localhost:8080/rest-api/dl4j/we/uploadModel'
  });
  
  uploader.onAfterAddingFile = function($modelFile) {
      console.info('onAfterAddingFile', $modelFile);
  
      var fd = new FormData();
  
      fd.append('file', $modelFile.file);
  
      $http.post($modelFile.url, fd, {
          headers: {
              'Content-Type': 'multipart/form-data'
          }, 
          params: {'file' : $modelFile.file}
      })
      .then(
          function (data) {
              alert("upload success");
          }, 
          function (data, status) {
              alert("upload error");
          }
       );
  
  };
  </code></pre>
  
  <p>However, I am getting <code>400 Bad Request</code> as server response. </p>
  
  <p>Any idea what the problem is?</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>I saw that an internal exception got thrown on the server side stating:</p>
  
  <blockquote>
    <p><code>org.springframework.web.multipart.support.MissingServletRequestPartException</code>: Required request part 'file' is not present</p>
  </blockquote>
  
  <p>I thought that I am setting this already - how can I make this right?</p>