如何从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); 

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...