Share via

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 Security | Microsoft Graph
0 comments No comments

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.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.