Hi @Kelly ,
Please refer to this post: https://stackoverflow.com/questions/49776955/how-to-upload-a-large-document-in-c-sharp-using-the-microsoft-graph-api-rest-cal
Create upload session
// Create upload session
// POST /v1.0/drive/items/01KGPRHTV6Y2GOVW7725BZO354PWSELRRZ:/SWEBOKv3.pdf:/microsoft.graph.createUploadSession
var uploadSession = await graphClient.Drive.Items[itemId].ItemWithPath("SWEBOK.pdf").CreateUploadSession().Request().PostAsync();
Create the task
// Create task
var maxChunkSize = 320 * 1024; // 320 KB - Change this to your chunk size. 5MB is the default.
var largeFileUpload = new LargeFileUpload(uploadSession, graphClient, stream, maxChunkSize);
Create upload monitor
public class MyProgress : IProgressCallback
{
public void OnFailure(ClientException clientException)
{
Console.WriteLine(clientException.Message);
}
public void OnSuccess(DriveItem result)
{
Console.WriteLine("Download completed with id below");
Console.WriteLine(result.Id);
}
public void UpdateProgress(long current, long max)
{
long percentage = (current * 100) / max ;
Console.WriteLine("Upload in progress. " + current + " bytes of " + max + "bytes. " + percentage + " percent complete");
}
}
Upload the file
uploadedFile = await largeFileUpload.ResumeAsync(new MyProgress());
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.