UWP: Upload large files to OneDrive using OneDrive SDK

限于喜欢 提交于 2020-01-03 05:50:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!