[英]Microsoft Graph - .NET SDK - OneDrive Large File Upload (> 4MB in size)
使用適用於 Microsoft Graph 的 .NET SDK,您可以上傳(小)文件。 示例在這里。
如何使用 .NET SDK 上傳大文件(> 4MB)?
換句話說,是否可以利用 SDK 來實現“使用上傳會話上傳大文件” ?
這是我最近使用 Microsoft Graph .Net SDK 編寫的代碼。 需要 GraphServiceClient(graphClient) 身份驗證。
if (fileSize.MegaBytes > 4)
{
var session = await graphClient.Drive.Root.ItemWithPath(uploadPath).CreateUploadSession().Request().PostAsync();
var maxSizeChunk = 320 * 4 * 1024;
var provider = new ChunkedUploadProvider(session, graphClient, stream, maxSizeChunk);
var chunckRequests = provider.GetUploadChunkRequests();
var exceptions = new List<Exception>();
var readBuffer = new byte[maxSizeChunk];
DriveItem itemResult = null;
//upload the chunks
foreach (var request in chunckRequests)
{
// Do your updates here: update progress bar, etc.
// ...
// Send chunk request
var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, exceptions);
if (result.UploadSucceeded)
{
itemResult = result.ItemResponse;
}
}
// Check that upload succeeded
if (itemResult == null)
{
await UploadFilesToOneDrive(fileName, filePath, graphClient);
}
}
else
{
await graphClient.Drive.Root.ItemWithPath(uploadPath).Content.Request().PutAsync<DriveItem>(stream);
}
這將在 .NET Microsoft Graph 客戶端庫的下一版本中可用。 它將與 .NET OneDrive 客戶端庫中的功能相同。 您可以在我的工作分支中查看此內容。 您可以在 repo 中提供反饋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.