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" 'https://url....'
It works fine. I need to make this request from my Java application.
I have tried next code
URL image_url = Thread.currentThread().getContextClassLoader().getResource("jobs_image.jpg");
String path = image_url.getFile();
HttpResponse<String> response = Unirest.post(uploadUrl)
.header("cache-control", "no-cache")
.header("X-Restli-Protocol-Version", "2.0.0")
.header("Authorization", "Bearer " + token + "")
.field("file", new File(path))
.asString();
However, it returns status 400 Bad Request. Is there any way to call such request from Java?
This is a request from LinkedIn v2 API: https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context#upload-image-binary-file