The example below uses cURL to upload image file included as a binary file.
curl -i --upload-file /path/to/image.png --header \"Authorization: Token\" \'http
Below method will upload the image to linkedIn
Reference : https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/vector-asset-api#upload-the-image
private void uploadMedia(String uploadUrl,String accessToken) throws IOException {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization","Bearer "+accessToken);
byte[] fileContents = Files.readAllBytes(new
File("path_to_local_file").toPath());
HttpEntity entity = new HttpEntity<>(fileContents, headers);
restTemplate.exchange(uploadUrl,HttpMethod.PUT, entity, String.class);
}