I am trying to download files from OneDrive using below Microsoft Graph call:
using (var strm = await client.Drives[RemoteDriveId].Items[Id].Content.Request().GetAsync())
{
byte[] byteBuffer = new byte[4096];
filePath = System.IO.Path.Combine(folderPath, filename);
using (System.IO.FileStream output = new FileStream(filePath, FileMode.Create))
{
int bytesRead = 0;
do
{
bytesRead = contentStream.Read(byteBuffer, 0, byteBuffer.Length);
if (bytesRead > 0)
{
output.Write(byteBuffer, 0, bytesRead);
}
}
while (bytesRead > 0);
}
}
The issue with above code is that if the file size is large or network is slow, request time out exception is thrown in the SDK before the file is completely downloaded. I would like to download the file in chunks or increase the timeout. How can I achieve this using Microsoft graph SDK?
Code provided above contains error
Which is incorrect and should be:
and is a bit clumsy with
I refactored it a bit and decided to publish it here.
Correct code
...
You'll need to chunk the download with the Range header.