Yes, with something like this, I think
If the image is your payload, and if you want to customize the headers, you can post it like this:
HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "image/jpeg"); InputStream in = new ClassPathResource("myFile.jpg").getInputStream(); HttpEntity<byte[]> entity = new HttpEntity<>(IOUtils.toByteArray(in), headers); template.exchange("http://example.com/myFileUpload", HttpMethod.POST, entity , String.class);
Otherwise:
InputStream in = new ClassPathResource("myFile.jpg").getInputStream(); HttpEntity<byte[]> entity = new HttpEntity<>(IOUtils.toByteArray(in)); template.postForEntity("http://example.com/myFileUpload", entity, String.class);
source share