I have been trying to follow the examples to upload large files for onedrive from Ms Graph SDK but I cannot seem to figure out where the DriveUpload object resides or what nuget package I need to install to make this work. My code is as follows:
public async Task<Models.CloudStorage?> UploadFileByPathAsync(MemoryStream SourceFile, string DestinationPath, string RootFolderId = "")
{
if(RootFolderId == "")
{
RootFolderId = _armsFolderId;
}
using var stream = SourceFile;
// Use properties to specify the conflict behavior
// in this case, replace
var uploadSessionRequestBody = new DriveUpload.CreateUploadSessionPostRequestBody
{
Item = new DriveItemUploadableProperties
{
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" },
},
},
};
// Create the upload session
// itemPath does not need to be a path to an existing item
var uploadSession = await _graphServiceClient.Drives[RootFolderId].Root
.ItemWithPath(DestinationPath)
.CreateUploadSession
.PostAsync(uploadSessionRequestBody);
// Max slice size must be a multiple of 320 KiB
int maxSliceSize = 320 * 1024;
var fileUploadTask =
new LargeFileUploadTask<DriveItem>(uploadSession, stream, maxSliceSize);
var totalLength = stream.Length;
// Create a callback that is invoked after each slice is uploaded
IProgress<long> progress = new Progress<long>(prog => {
Console.WriteLine($"Uploaded {prog} bytes of {totalLength} bytes");
});
// Upload the file
var uploadResult = await fileUploadTask.UploadAsync(progress);
if (uploadResult.UploadSucceeded)
{
var response = uploadResult.ItemResponse;
Console.WriteLine(uploadResult.UploadSucceeded ?
$"Upload complete, item ID: {uploadResult.ItemResponse.Id}" :
"Upload failed");
}
}
The error I get over the conflit behavior is:
The type or namespace name 'DriveUpload' could not be found (are you missing a using directive or an assembly reference?)
I cannot find much information online regarding where to add this. Also, I am trying to understand the performance differences between this large file upload vs the method indicated here: https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http