如何解决如何从Microsoft图形API下载文件InputStream?
我正在关注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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。