12

I am using the following method in a web browser to fetch file contents of a DriveItem using the Microsoft Graph:

GET /drives/{drive-id}/items/{item-id}
// Get the @microsoft.graph.downloadUrl property of the returned DriveItem
GET {downloadUrl}

This requires two GET calls.

I am also aware of this API:

GET /drives/{drive-id}/items/{item-id}/content

As documented here:

Download the contents of a DriveItem.

But the /content endpoint has two problems:

  1. It returns a 302 Found response, causing a redirect which needs another roundtrip to fetch the contents
  2. The API doesn't work in a JavaScript application using XHR as mentioned in this article: OneDrive - CORS support

How can I fetch the file contents of a DriveItem in one request?

Hlynur
  • 491
  • 2
  • 11
  • I apologize if you are not looking for alternatives but since I cannot comment on your post, Have you tried copying the files from one folder to the target location? Instead of downloading the contents. I have uploaded all the necessary files to the one SharePoint folder using graph endpoint and started using a "copy" endpoint of the graph to move it to different folders. – Ashok Subedi Jan 10 '20 at 17:00
  • @AshokSubedi Thanks for your suggestion but I need to download the content of the file for further processing on the web client. – Hlynur Jan 10 '20 at 20:17
  • Why do you need to get the file in a single command? From the documentation you linked, Microsoft says you have to use two statements if you're using CORS. – catherinemohan Sep 16 '20 at 06:55
  • @catherinemohan It would reduce the number of roundtrips if I could get the file in one network request. The documented approach is not very efficient IMO so I was wondering if there is a better way. – Hlynur Sep 16 '20 at 14:38
  • Ah I see. It's not looking very promising unfortunately. It doesn't seem like Microsoft is going to change how this particular API call works anytime soon. Even the beta endpoint does the same redirect routing. – catherinemohan Sep 16 '20 at 16:43

0 Answers0