Announcement Announcement Module
No announcement yet.
RestTemplate with Multipart Files. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate with Multipart Files.

    Basically, I need to create a multipart that consists of a 3-Tuple ("srcFile", filename, fileContents). I have tried using a LinkedMultiValueMap<String, LinkedMultiValueMap<String, Object>>, but this results in an HttpConverter missing error.

    In curl this can be done as follows:
    curl -X POST -F "srcFile=@/local/file/;filename=/prepatch/file/"

  • #2
    This blogpost got me on the right track:

    Instead of representing the multipart files as LinkedMultiValueMap<String, LinkedMultiValueMap<String, Object>>, I needed to represent them as LinkedMultiValueMap<String, HttpEntity<?>> (the type in my case is String, could be FileSystemResource as well). This allowed me to set a HttpHeader for each part, which in turn allowed me to set the filename via the setContentDispositionFormData method. I actually made my parts object LinkedMultiValueMap<String, Object>, which consists of both LinkedMultiValueMap<String, String> and LinkedMultiValueMap<String, HttpEntity<String>>.