Microsoft Graph 下载文件内容返回 404 [英] Microsoft Graph download file content returns 404
问题描述
我尝试使用 Grpah API 下载文件.
I tried to download a file with Grpah API.
使用 API 浏览器测试,https://graph.microsoft.io/en-us/graph-explorer#
Tested with API browser, https://graph.microsoft.io/en-us/graph-explorer#
运行以下请求,获取文件/文件夹项目信息列表,
Ran following request, got list of file/folder item information,
https://graph.microsoft.com/v1.0/me/drive/root/children
对于其中一个文件项目,我能够获取项目信息.
And for one of the file item, I was able to get item information.
https://graph.microsoft.com/beta/me/drive/items/_an_item_id
但以下返回 HTTP 404.
But following returns HTTP 404.
https://graph.microsoft.com/beta/me/drive/items/_an_item_id/content
出现这种症状的原因是什么?
What will be the cause for this symptom?
推荐答案
不支持向 https://graph.microsoft.com/beta/me/drive/items/
端点通过 Graph Explorer.
It is not supported to perform request to https://graph.microsoft.com/beta/me/drive/items/<itemid>/content
endpoint via Graph Explorer.
通过 Grath Explorer 发送到 https://graph.microsoft.com/beta/me/drive/items/<itemid>/content
端点的请求作为 预检请求.服务器以 302-Redirect
响应,但由于 CORS 行为.
The request sent to https://graph.microsoft.com/beta/me/drive/items/<itemid>/content
endpoint via Grath Explorer is issued as a preflight request. The server responds with 302-Redirect
but redirects are not allowed for preflighted requests due to CORS behavior.
这里有一个关于如何下载文件的解决方法
Here is a workaround on how to download a file
以下驱动项资源请求:
https://graph.microsoft.com/beta/me/drive/items/<itemId>
返回 @microsoft.graph.downloadUrl
注释,其中包含文件资源的实际链接.
returns @microsoft.graph.downloadUrl
annotation which contains the actual link to file resource.
检索驱动器项资源后,对来自 @microsoft.graph.downloadUrl
的 url 执行另一个 GET 请求以返回实际文件.
Once the drive item resource is retrieved, perform another GET request to url from @microsoft.graph.downloadUrl
to return the actual file.
这篇关于Microsoft Graph 下载文件内容返回 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!