Skip to content

Instantly share code, notes, and snippets.

@NahianAhmed
Last active July 21, 2022 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NahianAhmed/08f7fb331f01dbc44fb23a094dc320c8 to your computer and use it in GitHub Desktop.
Save NahianAhmed/08f7fb331f01dbc44fb23a094dc320c8 to your computer and use it in GitHub Desktop.
Upload/Send File from Microservice one to other Using Rest Template Java
public void sendCommunityData(File zippedFile) {
try {
HttpHeaders headers = New HttpHeaders();
String url = "You url";
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
requestBody.add("file", new FileSystemResource(zippedFile.getAbsolutePath()));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
log.info("File send to Api");
} catch (Exception ex) {
log.error(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment