title: Send JSON and Image with single request. Angular + Spring Boot
body: <p><strong>Spring Rest Controller</strong></p>
  
  <pre><code>@PostMapping(
      value = "/post",
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}
  )
  public ResponseEntity&lt;User&gt; handleFileUpload(@RequestParam("user") User user, @RequestPart("file") MultipartFile file) {
      // do something with User and file
      return ResponseEntity.ok().build();
  }
  </code></pre>
  
  <p><strong>Angular Service</strong></p>
  
  <pre><code>@Injectable()
  export class UploadFileService {
  
    constructor(private http: HttpClient) { }
    pushFileToStorage(file: File): Observable&lt;HttpEvent&lt;{}&gt;&gt; {
      let formdata: FormData = new FormData();
      formdata.append('file', file);
      formdata.append('user', JSON.stringify(new User('John', 12)))
  
      const req = new HttpRequest('POST', '/post', formdata, {
        reportProgress: true,
      });
  
      return this.http.request(req);
    }
  }
  </code></pre>
  
  <p>When I try to send the request I get <strong><code>500 Internal Server Error.</code></strong> </p>
  
  <p><strong>Here's a request header</strong></p>
  
  <pre><code>POST /post HTTP/1.1
  Host: localhost:4200
  Connection: keep-alive
  Content-Length: 152881
  Accept: application/json, text/plain, */*
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundarydaQb5yaWw2xu1V9r
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  </code></pre>
  
  <p><strong>Request payload</strong></p>
  
  <pre><code>------WebKitFormBoundarydaQb5yaWw2xu1V9r
  Content-Disposition: form-data; name="file"; filename="Screen Shot 2017-10-24 at 8.49.13 PM.png"
  Content-Type: image/png
  
  
  ------WebKitFormBoundarydaQb5yaWw2xu1V9r
  Content-Disposition: form-data; name="user"
  
  {"name":"John","age":12}
  ------WebKitFormBoundarydaQb5yaWw2xu1V9r--
  </code></pre>
  
  <p>Note: If in Spring rest controller I change parameter type User to String it works.</p>
  
  <p>Question: How to send request from Angular so that on Spring I can get User and MultipartFile, instead of String.</p>