title: Spring Required request part 'file' is not present
body: <p>I'm trying to upload an image with a form, it's going to be the profile picture, but I get the error:</p>
  
  <blockquote>
    <p>Required request part 'file' is not present</p>
  </blockquote>
  
  <p>I'm really new with spring, so I don't know what's wrong here's part of the code:</p>
  
  <p>This is the form</p>
  
  <pre><code>&lt;form th:action="@{/form}" th:object="${cliente}" method="post" enctype="multipart/form-data"&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label&gt;Nombre&lt;/label&gt;
          &lt;input class="form-control" type="text" th:field="*{nombre}" placeholder="Nombre"/&gt;
          &lt;small class="form-text text-danger" th:if="${#fields.hasErrors('nombre')}" th:errors="*{nombre}"&gt;&lt;/small&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;    
          &lt;label&gt;Apellido&lt;/label&gt;
                      &lt;input class="form-control" type="text" th:field="*{apellido}" placeholder="Apellido"/&gt;
          &lt;small class="form-text text-danger" th:if="${#fields.hasErrors('apellido')}" th:errors="*{apellido}"&gt;&lt;/small&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;    
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input class="form-control" type="text" th:field="*{email}" placeholder="correo@ejemplo.com"/&gt;
          &lt;small class="form-text text-danger" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"&gt;&lt;/small&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;    
          &lt;label&gt;Fecha&lt;/label&gt;
          &lt;input class="form-control" type="text" th:field="*{createAt}" placeholder="DD/MM/YYYY"/&gt;
          &lt;small class="form-text text-danger" th:if="${#fields.hasErrors('createAt')}" th:errors="*{createAt}"&gt;&lt;/small&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Imagen&lt;/label&gt;
          &lt;input type="file" name="file" class="form-control" th:field="*{foto}"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;    
          &lt;input class="btn btn-primary" type="submit" value="Guardar Cambios" /&gt;
      &lt;/div&gt;
  
   &lt;input type="hidden" th:field="*{id}" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the controller function</p>
  
  <pre><code>@RequestMapping(value="/form", method=RequestMethod.POST)
      public String guardar(@Valid Cliente cliente, BindingResult result, 
  @RequestParam("file") MultipartFile foto, RedirectAttributes flash) {
  
      String mensaje;
  
      if(result.hasErrors()) {
          return "form";
      }
  
      if(!foto.isEmpty()) {
          Path directorioRecursos = Paths.get("src//main//resources//static/uploads");
          String pathRoot = directorioRecursos.toFile().getAbsolutePath();
          try {
              byte[] bytes = foto.getBytes();
  
              Path rutaCompleta = Paths.get(pathRoot + "//" + foto.getOriginalFilename());
  
              Files.write(rutaCompleta, bytes);
  
              flash.addFlashAttribute("info", "Foto subida correctamente");
  
              cliente.setFoto(foto.getOriginalFilename());
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      if(cliente.getId() != null) {
          mensaje = "Cliente actualizado correctamente";
      }
      else {
          mensaje = "Cliente creado correctamente";
      }
  
      clienteservice.save(cliente);
      flash.addFlashAttribute("success", mensaje);
      return "redirect:listar";           
  }
  </code></pre>
  
  <p>This is my application properties</p>
  
  <pre><code>spring.http.multipart.file-size=10MB
  spring.http.multipart.max-request-size=10MB
  spring.http.multipart.enabled=true
  </code></pre>
  
  <p>Can you see what's wrong?</p>