Graph DriveItem Content Stream?

Bradley Plett 36 Reputation points
2021-12-09T22:33:19.357+00:00

I want to be able to download a large file using Graph. To do so, I need to "chunk" the file, because it's too large to fit into the memory available. Unfortunately the only call I know reads the entire file into memory immediately. Is there a way to avoid this? What call should I be using?

The call I'm using is:
graphClient.Drives[driveId].Items[itemId].Content.Request().GetAsync()
I want to use "CopyToAsync" with a buffer size to send this stream to my response stream, but it blows up on a memory exception before I can.

Any help would be much appreciated!

P.S. Why are there no tags for "Graph.Drives"?!?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,557 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Diya Ahuja 5 Reputation points
    2023-06-30T18:09:28.4+00:00

    To download a large file using Microsoft Graph, you can use the CreateUploadSession API to create an upload session. This will allow you to upload the file in chunks, which will help to avoid memory exceptions. The API call you need to use is POST /drives/{driveId}/items/{itemId}/createUploadSession. For more information about this API, see the Microsoft Graph documentation.

    0 comments No comments