title: How to pass multipart file along with file name to post method using Apache httpclient 3.x?
body: <p>service code:</p>
  
  <pre><code>    @RequestMapping(value="/uploadFile", method=RequestMethod.POST, consumes = "multipart/form-data")
  public String uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("filePath") String filePath){
  //logic here
  }
  </code></pre>
  
  <p>Part of the client code:</p>
  
  <pre><code>public static synchronized String responseOfPost(String restUrl, FileSystemResource file,String filePath) {
      PostMethod post = new PostMethod(restUrl);
      HttpClient client = new HttpClient();
      post.setParameter("filePath", filePath);
      try {
          Part[] parts = {new FilePart("file",file.getFile())};
          post.addRequestHeader("Content-Type", "multipart/form-data; boundary=Endedlogging");
          if (file != null) {
              post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
          }
          client.executeMethod(post);
          String response = post.getResponseBodyAsString();
      } catch (final IOException e) {
          e.printStackTrace();
      } 
      return null;
  }
  </code></pre>
  
  <p>this is the error I am getting:</p>
  
  <pre><code>org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'file' is not present
      at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:251)
      at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:96)
      at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
      at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
  </code></pre>
  
  <p>How can I pass multipart file("file") and filePath("filePath") to POST method in client code? <strong>NOT FROM UI</strong></p>