简体   繁体   English

Microsoft Graph - .NET SDK - OneDrive 大文件上传(> 4MB 大小)

[英]Microsoft Graph - .NET SDK - OneDrive Large File Upload (> 4MB in size)

Using the .NET SDK for Microsoft Graph, you can upload (small) files.使用适用于 Microsoft Graph 的 .NET SDK,您可以上传(小)文件。 Example here .示例在这里

How can I upload a large file (> 4MB) using the .NET SDK?如何使用 .NET SDK 上传大文件(> 4MB)?

In other words, can the SDK be utilized to implement "Upload large files with an upload session" ?换句话说,是否可以利用 SDK 来实现“使用上传会话上传大文件”

Here is the code I wrote recently using Microsoft Graph .Net SDK.这是我最近使用 Microsoft Graph .Net SDK 编写的代码。 GraphServiceClient(graphClient) authentication is required.需要 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);
                    }

This will be available in the next release of .NET Microsoft Graph client library.这将在 .NET Microsoft Graph 客户端库的下一版本中可用。 It will work the same as the functionality in the .NET OneDrive client library.它将与 .NET OneDrive 客户端库中的功能相同。 You can review this in my working branch .您可以在我的工作分支中查看此内容。 You can provide feedback in the repo.您可以在 repo 中提供反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Graph API 将文件 (&gt; 4MB) 上传到 OneDrive - Upload file (> 4MB) to OneDrive using Graph API 如何使用 Microsoft Graph API rest 调用在 c# 中上传超过 4MB - How to upload more than 4MB in c# using Microsoft Graph API rest calls 使用 Microsoft Graph 将 C# Asp.Net Core 中的文件上传到 Sharepoint/OneDrive,无需用户交互 - Upload a file in C# Asp.Net Core to Sharepoint/OneDrive using Microsoft Graph without user interaction 使用 Microsoft Graph 将新文件上传到 onedrive c# asp.net - Upload new file to onedrive using microsoft graph c# asp.net 无法使用 Microsoft Graph SDK 上传文件 - Unable to upload file using Microsoft Graph SDK Microsoft Graph Api 在文件夹中上传大文件 - Microsoft Graph Api Upload Large File in a folder UWP:使用OneDrive SDK将大文件上传到OneDrive - UWP: Upload large files to OneDrive using OneDrive SDK Microsoft Graph .Net API:共享的OneDrive文件夹 - Microsoft Graph .Net API: Shared OneDrive folder 使用Microsoft图表将文件上传到onedrive以进行业务 - Uploading file to onedrive for business using Microsoft graph 使用 Microsoft Graph API 将文件上传到 MVC 应用程序中的 onedrive,权限错误 - Using Microsoft Graph API to upload file to onedrive in MVC Application, Error with permissions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM