title: Spring RestTemplate POST file with UTF-8 filename
body: <p>I'm using Spring RestTemplate to perform POST request sending a PDF file. The filename contains some UTF-8 characters (e.g. é, è, à, ê, ë).</p>
  
  <p>The problem is that after sending the request, on the other side where the request is received, the filename doesn't have the expected UTF-8 characters, and I have something like ?popi?.pdf instead.</p>
  
  <p>I've tried to explicitly set UTF-8 charset in RestTemplate, but it still doesn't work.</p>
  
  <p>Here is my code,</p>
  
  <pre><code>public SomeThing storeFile(InputStream content, String fileName) {
      Charset utf8 = Charset.forName("UTF-8");
      RestTemplate restTemplate = new RestTemplate();
  
      HttpHeaders headersFile = new HttpHeaders();
      headersFile.setContentType(MediaType.APPLICATION_OCTET_STREAM);
      headersFile.setContentDispositionFormData("file", fileName);
      List&lt;Charset&gt; listCharSet = new ArrayList&lt;Charset&gt;();
      listCharSet.add(utf8);
  
      headersFile.setAcceptCharset(listCharSet);
  
      InputStreamResource inputStreamResource = new InputStreamResource(content);
      HttpEntity&lt;InputStreamResource&gt; requestEntityFile = new HttpEntity&lt;&gt;(inputStreamResource, headersFile);
  
      MultiValueMap&lt;String, Object&gt; multipartRequest = new LinkedMultiValueMap&lt;&gt;();
      multipartRequest.add("file", requestEntityFile);
  
      RestTemplate newRestTemplate = new RestTemplate();
  
      MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
      HttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
      newRestTemplate.getMessageConverters().add(0, stringHttpMessageConverter);
      newRestTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
      FormHttpMessageConverter convForm = new FormHttpMessageConverter();
      convForm.setCharset(utf8);
      newRestTemplate.getMessageConverters().add(convForm);
  
      HttpHeaders header = new HttpHeaders();
      header.setContentType(MediaType.MULTIPART_FORM_DATA);
      HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;&gt;(multipartRequest, header);
      ResponseEntity&lt;String&gt; result = newRestTemplate.postForEntity(env.getProperty("core.endpoint") + "/documents", requestEntity, String.class);
  
  }
  </code></pre>