microsoft graph onedrive upload file code example

Example: C# graph api upload file one drive

/// <summary> 
    /// Take a file and upload it to the service 
    /// </summary> 
    /// <param name="fileToUpload">The file that we want to upload</param> 
    /// <param name="uploadToSharePoint">Should we upload to SharePoint or OneDrive?</param> 
    public async Task UploadSmallFile(StorageFile fileToUpload, bool uploadToSharePoint) 
    { 
        Stream fileStream = (await fileToUpload.OpenReadAsync()).AsStreamForRead(); 
        DriveItem uploadedFile = null; 

        // Do we want OneDrive for Business/Consumer or do we want a SharePoint Site? 
        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); 
        } 
    }