问题
I can upload "small" files (< 100 MB) using the following code:
await OneDriveClient
.Drive
.Special
.AppRoot
.Children["filename"]
.Content
.Request()
.PutAsync<Item>(contentStream);
For Large files (> 100 MB) I read that you have to create an Upload Session
.
Something like this?
UploadSession uSession = await OneDriveClient
.Drive
.Special
.AppRoot
.Children["filename"]
.CreateSession(VarChunkedUploadSessionDescriptor)
.Request()
.PostAsync();
I am not sure what steps are after this? (Or even this is the right step!). Would appreciate some spoon-feeding :) Thanks in Advance!
回答1:
The sdk is a bit confusing on this. Note, the ItemWithPath is without the drive root....
//uploadPath = "/documentname.docx";
//filename = "documentname.docx";
var request = service.OneDriveClient.Drive.Root.ItemWithPath(uploadPath).CreateSession(new ChunkedUploadSessionDescriptor() { Name = Uri.EscapeUriString(System.IO.Path.GetFileName(filename)) }).Request();
var session = request.PostAsync().Result;
using (var stream = new System.IO.FileStream(filename, System.IO.FileMode.Open))
{
if (stream != null)
{
Microsoft.OneDrive.Sdk.Helpers.ChunkedUploadProvider chunk = new Microsoft.OneDrive.Sdk.Helpers.ChunkedUploadProvider(
session, client, stream);
var item = chunk.UploadAsync().Result;
}
}
来源:https://stackoverflow.com/questions/36551048/uwp-upload-large-files-to-onedrive-using-onedrive-sdk