title: Uploading a file via Spring
body: <p>I have a dev server which revolves angular 2 at localhost: 4200, and tomcat with Spring on localhost: 8080.
  I try to upload a file to the server in the following manner:</p>
  
  <p><strong>angular code:</strong> </p>
  
  <pre><code>uploadAvatar(file:File){
      let xhr = new XMLHttpRequest()
      xhr.open("POST",`http://localhost:8080/api/upload/avatar`)
      xhr.setRequestHeader("Content-Type","multipart/form-data")
      xhr.send(file)
  }
  </code></pre>
  
  <p><strong>Controller code Spring:</strong></p>
  
  <pre><code>@RequestMapping(value = "/api/upload/avatar", method = RequestMethod.POST)
  public String uploadFile(MultipartFile file){
      log.info(file);
      return file.getName();
  }
  </code></pre>
  
  <p>But after trying to download a file error appears in the java-console:</p>
  
  <pre><code>org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; 
  nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
  </code></pre>
  
  <p>How do I fix this error?</p>
  
  <p>Thank you.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>The "duplicate" is used with Spring MVC + JSP, I'm trying to download a file via Ajax. And the version of the decision does not help me given there.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p><code>Spring Boot(v1.4.3.RELEASE)</code><br>
  I use the java configuration, if you want I will give an example of a full configuration.</p>