Hi I am trying to upload an image to Linkedin via Spring RestTemplate, the steps followed are as follows 1.Initialize the upload and the upload url 2.Use the upload url to PUT the image linked in server
below is the method for step 2
public String uploadImageToURL(MultipartFile file, String uploadURL) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.add("Authorization", "Bearer Redacted");
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", file.getBytes());
HttpEntity<MultiValueMap<String, Object>> reqEntity = new HttpEntity<>(body, headers);
try {
ResponseEntity<String> resp = new RestTemplate().exchange(uploadURL, HttpMethod.PUT, reqEntity, String.class);
} catch (HttpClientErrorException e) {
e.printStackTrace();
}
}
the method is giving -
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: [no body]
I am not able to figure out what's wrong here also from the documentation of linkedin apis its not clear they have given a basic curl request which working fine on postman but programmatically its not working
Curl for the above method as per documentation
Any help is appreciated, I have tried giving content-type to header as image/png but no effect.
PS: I have already referred this link Linkedin v2 API Image upload get error 400 Bad Request but its not helping