title: Spring Controller @RequestBody with file upload is it possible?
body: <p>I have a Controller like this and I want to submit a form with file uploading as well as some form data like label as shown below. Also, I want to do that using @RequestBody so I can use the @Valid annotation on the wrapper as more variables will be added.</p>
  
  <pre><code>public @ResponseBody WebResponse&lt;Boolean&gt; updateEUSettings(
      final Locale locale,
      @Validated @ModelAttribute final EUPSettingsWrapper endUserPortalSettingsWrapper) {
  }
  </code></pre>
  
  <p>And my wrapper is:</p>
  
  <pre><code>public class EUPSettingsWrapper {
  
      private String label;
      private MultipartFile logo;
  // getter , setters..etc...
  }
  </code></pre>
  
  <p>But I would like to convert it into a @RequestBody from ModelAttributes. </p>
  
  <p>The way I'm trying is by having the file upload separated as request parameter like this:</p>
  
  <pre><code>public @ResponseBody WebResponse&lt;Boolean&gt; updateEUSettings(
      final Locale locale,
      @Validated @RequestBody final EUPSettingsWrapper endUserPortalSettingsWrapper, 
      @RequestParam(value = "file1", required = true) final MultipartFile logo) {
  
      endUserPortalSettingsWrapper.setLogo(logo);
  
      // ...
  }
  </code></pre>
  
  <p>In my mock MVC, I am setting:</p>
  
  <pre><code>getMockMvc().perform(fileUpload(uri).file(logo)
                          .accept(MediaType.APPLICATION_JSON)
                          .content(JSONUtils.toJSON(wrapper))
                          .contentType(MediaType.MULTIPART_FORM_DATA))
                          .andExpect(status().isOk());
  </code></pre>
  
  <p>But I'm getting an error like this which says:</p>
  
  <pre><code>org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data' not supported
  </code></pre>
  
  <p>Does anyone have a good idea of how Multipart file uploads can be used with @RequestBody? Anything I am doing wrong above?</p>