title: Angular - Spring : how to pass file + json object to WS?
body: <p>On angular side, I pass my file + json object :</p>
  
  <pre><code>const formData: FormData = new FormData();
  formData.append('fabricDTO', JSON.stringify(classToPlain(fabric)));
  formData.append('file', picture);
  return this.http.Post(this.SAVE_FABRIC_URL, formData)
  </code></pre>
  
  <p>And on java side I try to get the file and json object. I have a DTO with same structure :</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "fabric")
  public class FabricController {
  
      @Autowired
      IFabricService fabricService;
  
  
      @PreAuthorize("#oauth2.hasScope('foo') and #oauth2.hasScope('read')")
      @RequestMapping(method = RequestMethod.GET)
      public ResponseEntity&lt;Collection&lt;FabricDTO&gt;&gt; getUserFabrics() {
          ...
      }
  
      @PreAuthorize("#oauth2.hasScope('foo') and #oauth2.hasScope('read')")
      @RequestMapping(method = RequestMethod.POST)
      public ResponseEntity saveUserFabrics(@RequestBody FabricDTO fabricDTO, 
              @RequestParam("file") MultipartFile file) {
      ...
      }
  
  }
  </code></pre>
  
  <p>In config I do have multipartResolver</p>
  
  <pre><code>@Bean(name = "multipartResolver")
      public CommonsMultipartResolver multipartResolver() {
          CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
          multipartResolver.setMaxUploadSize(1000000);
          return multipartResolver;
      }
  </code></pre>
  
  <p>This is what I see in chrome console, in Form data :</p>
  
  <pre><code>fabricDTO: {"fabricTypeId":4,"comment":"sdf"}
  file: (binary)
  </code></pre>
  
  <p>FabricDTO is :</p>
  
  <pre><code>private int id;
  private float length;
  private String comment;
  private int fabricTypeId;
  </code></pre>
  
  <p>But when I send call the WS I got error : </p>
  
  <blockquote>
    <p>Resolved [org.springframework.web.HttpMediaTypeNotSupportedException:
    Content type
    'multipart/form-data;boundary=----WebKitFormBoundarymeuYlXb7Tsiyovtn;charset=UTF-8'
    not supported]</p>
  </blockquote>
  
  <p>I believe that I shouldn't use @RequestBody to get the DTO, I tried with @RequestParam but all DTO values are null.</p>
  
  <p>Should I pass my data in a different way?</p>
  
  <p>If I don't add the DTO in formData and I comment the "@RequestBody FabricDTO fabricDTO" in controller, I'm able to get the file.</p>
  
  <p>Thx</p>