title: Spring org.springframework.web.multipart.support.MissingServletRequestPartException, Required request part 'file' is not present
body: <p>I am trying to send a file to the controller by using it in FormBodyPart, rather than directly sending the file to it. Here is the code for making a collection of files</p>
  
  <pre><code>private void addFile(Collection&lt;FormBodyPart&gt; parts, File inputFile, String fileType)
          throws ClassificationException {
      if (inputFile == null) {
          throw new ClassificationException("Null input file provided");
      }
      if (!inputFile.exists()) {
          throw new ClassificationException("Input file not found: " + inputFile.getAbsolutePath());
      }
      if (fileType != null) {
  
          String charset = "UTF-8";
          parts.add(new FormBodyPart("file", new FileBody(inputFile, fileType, charset)));
  
      } else {
          parts.add(new FormBodyPart("file", new FileBody(inputFile, inputFile.getName())));
      }
  }
  </code></pre>
  
  <p>Parts collection is an arraylist, which would contain the files.</p>
  
  <p>Here is my code for setting Http Entity</p>
  
  <pre><code>HttpPost httppost = new HttpPost("http://localhost:9000/upload1");
              MultipartEntity reqEntity1 = new MultipartEntity();
              FormBodyPart part1;
              for (Iterator i$ = parts.iterator(); i$.hasNext(); reqEntity1.addPart(part1)) {
                  part1 = (FormBodyPart) i$.next();
                  System.out.println(part1.getHeader());
              }
  
              httppost.setEntity(reqEntity1);
              HttpResponse response = httpclient.execute(httppost);
              System.out.println(response);
  </code></pre>
  
  <p>My method declaration of controller is</p>
  
  <p><code>String index(@RequestParam("file") MultipartFile uploadfile)</code></p>
  
  <p>I am getting an error from the server stating </p>
  
  <blockquote>
    <p>[400] {"timestamp":1474898550131,"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'file' is not present","path":"/upload1"}</p>
  </blockquote>
  
  <p>My dispatcher.xml already contains bean of multipartResolver.</p>
  
  <p>I am fairly new to web services and might be doing some kind of silly mistake. Please help me out,thanks in advance</p>