title: How to convert this curl request to Http post request for file upload in java?
body: <p>Following is my curl request:</p>
  
  <pre><code>curl -X POST --data-urlencode 'data1@/Users/Documents/file.csv' http://localhost:8000/predict
  </code></pre>
  
  <p>Following is my equivalent Java implementation.</p>
  
  <pre><code>String filePath = inputFilePath;
          String url = inputUrl;
          File file = new File(filePath);
          CloseableHttpClient httpClient = HttpClients.createDefault();
          HttpPost uploadFile = new HttpPost(inputUrl);
          uploadFile.addHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8");
  
          MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  
          FileBody fileBody = new FileBody(new File(inputFilePath));
  
          HttpEntity reqEntity = MultipartEntityBuilder.create()
                  .addPart("data1", fileBody)
                  .build();
  
  
          uploadFile.setEntity(reqEntity);
          CloseableHttpResponse response = null;
          try {
              response = httpClient.execute(uploadFile);
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  </code></pre>
  
  <p>I am trying to invoke my R Rest API endpoint from my Java HTTP post.</p>
  
  <pre><code>#* @post /predict
  mypredict &lt;- function(data1) {
    print(data1)
  
  }
  </code></pre>
  
  <p>(1) Is my equivalent Java HTTP Post request correct?
  (2) I am able to invoke the R rest endpoint using my curl command. But for some reason when i sent the POST request through my Java code, i see that data1 is not being passed as part of post request. I see this error in R.</p>
  
  <pre><code>&lt;simpleError in print(data1): argument "data1" is missing, with no default&gt;
  </code></pre>
  
  <p>I feel my Java equivalent curl implementation is wrong. Can someone help?</p>