microsoft graph onedrive upload file code example
Example: C# graph api upload file one drive
public async Task UploadSmallFile(StorageFile fileToUpload, bool uploadToSharePoint)
{
Stream fileStream = (await fileToUpload.OpenReadAsync()).AsStreamForRead();
DriveItem uploadedFile = null;
if (uploadToSharePoint)
{
uploadedFile = await graphClient.Sites["root"].Drive.Root.ItemWithPath(fileToUpload.Name).Content.Request().PutAsync<DriveItem>(fileStream);
}
else
{
uploadedFile = await graphClient.Me.Drive.Root.ItemWithPath(fileToUpload.Name).Content.Request().PutAsync<DriveItem>(fileStream);
}
}