Вы можете сделать что-то вроде этого:
public void uploadFileTemplate() throws IOException {
MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
bodyMap.add("user-file", getUserFileResource());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyMap, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange("http://localhost:8080/upload",
HttpMethod.POST, requestEntity, String.class);
System.out.println("response status: " + response.getStatusCode());
System.out.println("response body: " + response.getBody());
}
public static Resource getUserFileResource() throws IOException {
//todo replace tempFile with a real file
Path tempFile = <path-to-your-imagefile>
System.out.println("uploading: " + tempFile);
File file = tempFile.toFile();
return new FileSystemResource(file);
}