title: Spring Rest Template creating multipart form/data client working like a postman throws non convertable exception
body: <p>I want to turn this postman client with multipart/form-data header request to a spring template client.</p>
  
  <p><a href="https://i.stack.imgur.com/0AD9O.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0AD9O.png" alt="postmanClient"></a></p>
  
  <p>Right now, I have a basic rest controller which works well.</p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class MainConroller {
  
      private static final Logger log = LoggerFactory.getLogger(MainConroller.class);
      @Autowired
      private MainService mainService;
  
      public MainConroller(MainService mainService) {
          this.mainService = mainService;
      }
  
      @PostMapping("/mails/send")
      public void send(
              @RequestParam("usertoken") String usertoken,
              @RequestParam("sendTo") String sendTo,
              @RequestParam("subject") String subject,
              @RequestParam("content") String content,
              @RequestParam(required = false, name = "files") List&lt;MultipartFile&gt; multipartFiles) {
          log.debug("{}, {}, {}, {}", usertoken, sendTo, subject, content);
  
          mainService.processMessage(usertoken, sendTo, subject, content, multipartFiles);
  
      }
  
  }
  </code></pre>
  
  <p>I need to, however, create a rest client so I used a rest template, it right now looks like this:</p>
  
  <pre><code>ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt; converters = new ArrayList&lt;&gt;(
              Arrays.asList(new MappingJackson2HttpMessageConverter(), new ResourceHttpMessageConverter(), new FormHttpMessageConverter()));
      @Bean
      public RestTemplate restTemplate() {
          return new RestTemplate(converters);
      }
      File file = new File("*********");
  
              HttpHeaders httpHeaders = new HttpHeaders();
              httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
  
              MultiValueMap&lt;String, Object&gt; fileValueMap = new LinkedMultiValueMap&lt;&gt;();
              fileValueMap.add(file.getName(), file);
              fileValueMap.add(file.getName(), file);
              fileValueMap.add(file.getName(), file);
  
              HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; filesPart = new HttpEntity&lt;&gt;(fileValueMap, httpHeaders);
  
      //        String key values part
  
              MultiValueMap&lt;String, String&gt; stringPart = new LinkedMultiValueMap&lt;&gt;();
              stringPart.add("usertoken", "test");
              stringPart.add("sendTo", "test");
              stringPart.add("subject", "test");
              stringPart.add("content", "test");
  
              HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt; objectPart = new HttpEntity&lt;&gt;(stringPart, httpHeaders);
  
  
              MultiValueMap&lt;String, Object&gt; multiPartRequest = new LinkedMultiValueMap&lt;&gt;();
              multiPartRequest.add("ObjectPart", objectPart);
              multiPartRequest.add("FilesPart", filesPart);
  
  
              HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;&gt;(multiPartRequest, httpHeaders);
  
              String serverUrl = "****";
  
              restTemplate().postForEntity(serverUrl, requestEntity, String.class);
  </code></pre>
  
  <p>The problem is when I try to send the post request, It throws </p>
  
  <pre><code>Exception in thread "main" org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [org.springframework.util.LinkedMultiValueMap] and content type [multipart/form-data]
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>The solution on the client side is very simple, you can just send String values in the object values, which are going to be automatically casted to Strings via generics.</p>
  
  <p>Also, the files cannot be send just as files but you have to create FileSystemResource instead, here is the complete code of the client side:</p>
  
  <pre><code>@Service
  public class RestTemplatePost {
  
      @Bean
      public RestTemplate restTemplate() {
          return new RestTemplate();
      }
  
      public void prepareMessage() throws Exception {
  
  
          HttpHeaders httpHeaders = new HttpHeaders();
          httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
  
          MultiValueMap&lt;String, Object&gt; form = new LinkedMultiValueMap&lt;&gt;();
          form.add("usertoken", "test");
          form.add("sendTo", "test");
          form.add("subject", "test");
          form.add("content", "test");
          form.add("files", getTestFile());
          form.add("files", getTestFile());
  
          HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;&gt;(form, httpHeaders);
  
          String serverUrl = "******";
  
          restTemplate().postForEntity(serverUrl, requestEntity, String.class);
  
  
      }
  
      public static Resource getTestFile() throws IOException {
      Path testFile = Paths.get("C****");
      System.out.println("Creating and Uploading Test File: " + testFile);
      Files.write(testFile, "Hello World !!, This is a test file.".getBytes());
      return new FileSystemResource(testFile.toFile());
  }
  
  }
  </code></pre>