UWP:使用OneDrive SDK将大文件上传到OneDrive [英] UWP: Upload large files to OneDrive using OneDrive SDK
本文介绍了UWP:使用OneDrive SDK将大文件上传到OneDrive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下代码上传小的"文件(<100 MB):
I can upload "small" files (< 100 MB) using the following code:
await OneDriveClient
.Drive
.Special
.AppRoot
.Children["filename"]
.Content
.Request()
.PutAsync<Item>(contentStream);
对于大文件(> 100 MB),我读到您必须创建一个Upload Session
.
像这样吗?
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!
推荐答案
sdk在此方面有点令人困惑.注意,ItemWithPath没有驱动器根目录....
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;
}
}
这篇关于UWP:使用OneDrive SDK将大文件上传到OneDrive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文