Last active
July 21, 2022 04:08
-
-
Save NahianAhmed/08f7fb331f01dbc44fb23a094dc320c8 to your computer and use it in GitHub Desktop.
Upload/Send File from Microservice one to other Using Rest Template Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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