Reputation: 325
I tried to download a file with Grpah API.
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
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?
Upvotes: 2
Views: 2072
Reputation: 59358
It is not supported to perform request to https://graph.microsoft.com/beta/me/drive/items/<itemid>/content
endpoint via Graph Explorer.
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
The following drive item resource request:
https://graph.microsoft.com/beta/me/drive/items/<itemId>
returns @microsoft.graph.downloadUrl
annotation which contains the actual link to file resource.
Once the drive item resource is retrieved, perform another GET request to url from @microsoft.graph.downloadUrl
to return the actual file.
Upvotes: 1