Upload file (> 4MB) to OneDrive using Graph API

  • Thread starter Thread starter Mohamed Thaufeeq
  • Start date Start date
M

Mohamed Thaufeeq

Guest
I am trying to upload files to OneDrive using Graph API. The below code works fine when I upload files with size lesser than 4MB but it shows error when I try to upload files more than 4 MB. I went through this documentation but still I am not sure how can I get this work.

Below is my working code for files less than 4MB.

using (var client = new HttpClient())
{
var url = "https://graph.microsoft.com/v1.0" + $"/drives/{driveID}/items/{folderId}:/{originalFileName}:/content";
client.
DefaultRequestHeaders.Add("Authorization", "Bearer " + GetAccessToken());

byte[] sContents = System.IO.File.ReadAllBytes(filePath);
var content = new ByteArrayContent(sContents);

var response = client.PutAsync(url, content).Result.Content.ReadAsStringAsync().Result;
}



Please help


- Mohamed Thaufeeq A

Continue reading...
 
Back
Top