title: Upload file in Spring Boot REST API
body: <p>I am trying to upload a file using Spring Boot <code>@RestController</code>:</p>
  
  <pre><code>    @RequestMapping(value = "/register", method = RequestMethod.POST)
  public AppResponse registerUserFromApp(
          @RequestBody UserInfo userInfo,
          @RequestParam(value = "file", required = false) CommonsMultipartFile file,
          @RequestParam(value = "inviteCode", required = false) String inviteCode){
  </code></pre>
  
  <p>With this definition, I tried this Postman request:
  <a href="https://i.stack.imgur.com/9ZxgF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ZxgF.png" alt="Register API"></a>
  This doesn't work.</p>
  
  <p>I tried adding this to my <code>RequestMapping</code>:</p>
  
  <pre><code>@RequestMapping(value = "/register", method = RequestMethod.POST, consumes = "multipart/form-data")
  </code></pre>
  
  <p>This gives me the same error.</p>
  
  <p>For <code>userInfo</code>, I am sending the values as JSON in form-data fields itself as suggested by <a href="https://stackoverflow.com/a/43786496/3913366">another SO answer</a>. Doesn't work, same error.</p>
  
  <p>As suggested in some other SO answers, I also made sure that I wasn't sending any headers in Postman.</p>
  
  <p>I tried adding the following property in <code>application.properties</code> as well:</p>
  
  <pre><code>spring.http.multipart.enabled=false
  </code></pre>
  
  <p>Same error. I also tried <code>MultipartFile</code> instead of <code>CommonsMultipartFile</code>, no difference at all.</p>
  
  <p>What am I doing wrong? I want to send an image as a File and <code>UserInfo</code> object in the request as well. Postman examples will be really appreciated.</p>