title: Upload file from AngularJS to Spring Boot
body: <p>I'm using AngularJS to make my front end and Java with Spring Boot to make my back end. I'm trying to import/upload a xlsx, xls, or ods file from the Angular to my Java, but whatever I do, the request doesn't send my file!</p>
  
  <p>Java endpoint:</p>
  
  <pre><code>@PostMapping(value = "/upload/{type}")
  @ResponseBody
  private ResponseEntity&lt;List&lt;Rota&gt;&gt; importFile(@PathVariable("type") String type,
                                                @RequestParam(required = false, value = "file") MultipartFile fileParam, 
                                                @RequestBody MultipartFile  file) {
      System.out.println("File: " + file.getName());
      if(type.toUpperCase().equals("XLSX")){
          System.out.println("XLSX!");
      }else if(type.toUpperCase().equals("XLS")){
          System.out.println("XLS!");
      }else if(type.toUpperCase().equals("ODS")){
          System.out.println("ODS!");
      }else{
          System.out.println("OPS!");
          return new ResponseEntity&lt;&gt;(new ArrayList&lt;&gt;(), HttpStatus.UNSUPPORTED_MEDIA_TYPE);
      }
      return new ResponseEntity&lt;&gt;(new ArrayList&lt;&gt;(), HttpStatus.OK);
  }
  </code></pre>
  
  <p>My request-id made using an Angular class prepared to only make requests. I'll post here the code that we use normally in the project and the code that actually worked but I can't use it.</p>
  
  <p>DataFactory:</p>
  
  <pre><code>DataFactory.POST = function (url, entity, config = null) {
    if (url &amp;&amp; entity) {
      return $http
        .post(url, entity, config)
        .then(res =&gt; $q.resolve(res.data), error =&gt; $q.reject(error));
    }
  };
  </code></pre>
  
  <p>The code that actually worked:</p>
  
  <pre><code>var xhr = new XMLHttpRequest;
  xhr.open('POST', `${URL.CTM_ODS()}/rotas/upload/${type}`, true);
  xhr.send(formData);
  </code></pre>
  
  <p>When I use Postman, sending the file through the body, the back end receives null, but when I use form-data from Postman, works fine!
  Using the DataFactory I got the following stack on my back end:</p>
  
  <pre><code>WARN 16796 --- [p1002886236-126] org.eclipse.jetty.http.HttpParser        : badMessage: java.lang.IllegalStateException: too much data after closed for HttpChannelOverHttp@78fd8670{r=2,c=false,a=IDLE,uri=}
  </code></pre>