title: How I do the equivalent of this curl command using Spring's RestTemplate?
body: <p>I am successful posting a file to the same web service using the following:</p>
  
  <pre><code>curl -X POST http://&lt;someUrl&gt; -F "file=@/path/to/aFile.txt"
  </code></pre>
  
  <p>Now I am attempting to perform the same type of operation using Spring's RestTemplate with the caveat that I want to send a Java Object. Here is an example of what I tried:</p>
  
  <pre><code>File file = File.createTempFile("aaa","bbb");
  FileUtils.writeStringToFile(file, mapper.writeValueAsString(message), "UTF-8");
  
  MultiValueMap&lt;String, Object&gt; values = new LinkedMultiValueMap&lt;String, Object&gt;();
  values.add("file", new FileSystemResource(file));
  
  restTemplate.postForObject(URL, values, String.class);
  </code></pre>
  
  <p>Where mapper is an instance of Jackson's ObjectMapper (v1.9.6) and FileUtils is from Apache's Common.</p>
  
  <p>The REST service requires the content type to be multipart/form-data so what I attempted to do was write the Java Object as a JSON string to a temporary file and then post the temporary file. Unfortunately I am getting an HTTP 500 Internal Server Error.</p>
  
  <p>What am I doing wrong? Any suggestions as to how to do this?</p>