问题描述
我正在关注Graph APIs,以便从sharepoint下载文件。
尝试了此端点-https://graph.microsoft.com/v1.0/drives/{drive_id}/root:/{folder}/{file_name}:/content
尝试使用restTemplate获取InputStream。
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
httpHeaders.set(GraphConstant.AUTHORIZATION,TOKEN);
HttpEntity httpEntity = new HttpEntity(httpHeaders);
String downloadEndPoint = DOWNLOAD_FILE_ENDPOINT.replace(GraphConstant.DRIVE_ID,getDriveId(id)).replace("{folder}",folder).replace(GraphConstant.FILE_NAME,URLEncoder.encode(fileName,GraphConstant.UTF_8).replace("+","%20"));
ResponseEntity<InputStream> responseEntity = restTemplate.exchange(downloadEndPoint,HttpMethod.GET,httpEntity,InputStream.class);
if(responseEntity.getStatusCode().equals(HttpStatus.OK)){
return responseEntity.getBody();
}
responseEntity 返回responseEntity.getBody()为空。
Graph Download file API的返回类型是什么?这里有输入吗?
我正在使用SpringBoot应用程序,并使用restTemplate进行调用(不使用Microsoft SDK进行图形调用)。
解决方法
将ResponseEntity更改为ResponseEntity
ResponseEntity<byte[]> responseEntity = graphRestTemplate.exchange(DOWNLOAD_FILE_ENDPOINT,HttpMethod.GET,httpEntity,byte[].class,drive_id,entity_id,fileName);