title: Send a PDF attachment using Spring RestTemplate with Basic Auth and Custom headers
body: <p>I need to send a PDF attachment using PUT sort of like when you attach a document in POSTMAN <a href="https://i.stack.imgur.com/5y5qz.png" rel="nofollow noreferrer">POSTMAN EXAMPLE</a>. The service I'm using will only accept PDF files in the body of the request.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>// create new file
  FileSystemResource file = new FileSystemResource(new File("/Users/name/Documents/test.pdf"));
  MultiValueMap&lt;String, Object&gt; body = new LinkedMultiValueMap&lt;&gt;();
  body.add("file", file);
  
  // adding basic auth
  HttpHeaders headers = createHeaders(username, password);
  // required custom header
  headers.set("X-Async-Scope", timelineEntryId);
  HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;&gt;(body, headers);
  
  RestTemplate restTemplate = new RestTemplate();
  ResponseEntity&lt;String&gt; response = restTemplate.exchange(baseUrl, HttpMethod.PUT, requestEntity, String.class);
  </code></pre>
  
  <p>the problem is the <strong>response</strong> comes with a status code of <strong>415 Unsupported Media Type</strong> and I'm not sure why. is my HttpEntity body in the wrong format? </p>