title: Angular 8 Springboot File Upload hopeless
body: <p>Google 'Angular 8 Springboot File Upload'. I tried the first 3 pages. Couldn't upload a damn file.</p>
  
  <p>Furthest I got was:</p>
  
  <p>Resolved [org.springframework.web.multipart.MultipartException: Current request is not a multipart request]</p>
  
  <p>Tried everything I could.</p>
  
  <p>I just want to send a file from Angular and receive it in a spring boot rest controller.
  Could someone please help me out with that?</p>
  
  <p>Back End:</p>
  
  <pre><code>@PostMapping("/users/profile/upload")
  @ResponseStatus(HttpStatus.OK)
  public ResponseEntity&lt;String&gt; uploadData(@RequestParam("file") MultipartFile file)
          throws Exception {
      if (file == null) {
          throw new RuntimeException("You must select the a file for uploading");
      }
      String originalName = file.getName();
  
      // Do processing with uploaded file data in Service layer
      return new ResponseEntity&lt;String&gt;(originalName, HttpStatus.OK);
  }
  </code></pre>
  
  <p>Front end service:</p>
  
  <pre><code>uploadFile(file: File): Observable&lt;any&gt; {
  
  const formData = new FormData();
  
  formData.append('file', file, 'file');
  const headers = new HttpHeaders({
    'Content-Type': 'multipart/form-data'
  });
  const options = { headers };
  
  return this.http.post(`${this.baseUrl}/profile/upload`, formData, options);
  }
  </code></pre>