How to convert curl call with “-i --upload-file” into java Unirest or any other http request?

前端 未结 3 1101
孤城傲影
孤城傲影 2020-12-18 10:46

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         


        
3条回答
  •  执念已碎
    2020-12-18 11:13

    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);
          }
    

提交回复
热议问题