title: Spring Boot Required request part 'file' is not present
body: <p>I am trying to create a file upload utility and am getting the following error when I click on the <code>submit</code> button. It starts uploading and then suddenly has this error: </p>
  
  <pre><code>There was an unexpected error (type=Bad Request, status=400).
  Required request part 'file' is not present
  </code></pre>
  
  <p>I don't have a stacktrace, that's all that's displayed in my window or my console. I've looked for other solutions and they all ended up being someone forgot to include <code>name="file"</code> in their html file. I have made sure it's included and am still getting the error. </p>
  
  <p>Below is my upload form:</p>
  
  <pre><code>&lt;div id="custom-search-input"&gt;
  &lt;label&gt;Select a file to upload&lt;/label&gt;
      &lt;form action="/upload" enctype="multipart/form-data" method = "post"&gt; 
          &lt;div class="input-group col-md-12"&gt;
              &lt;input type="file" name="file" class="search-query form-control"/&gt;
              &lt;span class="input-group-btn"&gt;
                  &lt;button type="submit" class="btn btn-success"&gt;Upload &lt;/button&gt;
              &lt;/span&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is my controller method for uploading:</p>
  
  <pre><code>@Value("${upload.path}")
      private String path;
  
      @RequestMapping("/upload")
      public String upload(@RequestParam("file") MultipartFile file, Model model, HttpSession session) throws IOException {
              if(!file.isEmpty()) {
                  //Get the user
                  User user = (User) session.getAttribute("user");
                  //Get the file name
                  String fileName = file.getOriginalFilename();
                  InputStream is = file.getInputStream();
                  //Store the uploaded file into the users directory in the system path
                  Files.copy(is, Paths.get(path + user.getNetworkId() + "\\"  + fileName),StandardCopyOption.REPLACE_EXISTING);
  
              return "redirect:/success.html";
  
          } else {
  
              return "redirect:/index.html";
          }   
      }
  </code></pre>
  
  <p>Also would like to note I tried this for my upload method: </p>
  
  <pre><code>public String upload(@RequestParam(name="file",required=true) MultipartFile file, Model model, HttpSession session) 
  </code></pre>
  
  <p>For reference, <a href="http://zetcode.com/springboot/uploadfile/" rel="nofollow noreferrer">this</a> is what I was referrencing.</p>
  
  <p>As per some of the answers below, I tried creating a <code>PostMapping</code> method stand alone, as well as <code>@RequestMapping(value="/upload", method = RequestMethod.POST)</code> I am still getting the error.</p>