1

我正在关注Graph API从 Sharepoint 下载文件。

我试过这个端点: https ://graph.microsoft.com/v1.0/drives/{drive_id}/root:/{folder}/{file_name}:/content

InputStream使用restTemplate

 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.getBody()返回null

Graph Download file API的返回类型是什么?这里有任何输入吗?

我正在使用 SpringBoot 应用程序并使用 restTemplate 进行调用(不使用 Microsoft SDK 进行图形调用)。

4

1 回答 1

1

将 ResponseEntity 更改为 ResponseEntity<byte[]> 解决了我的问题。

ResponseEntity<byte[]> responseEntity = graphRestTemplate.exchange(DOWNLOAD_FILE_ENDPOINT,
            HttpMethod.GET,
            httpEntity,
            byte[].class,
            drive_id,
            entity_id,
            fileName); 
于 2020-09-24T06:48:48.390 回答