Sak*_*ket 1 onedrive microsoft-graph-api
我正在使用 Microsoft Graph SDK 在 OneDrive 中分块上传文件。我正在使用以下代码上传文件:
try
{
GraphServiceClient graphClient = this.GetGraphServiceClient(accessToken);
string fileName = Path.GetFileName(srcFilePath);
using (var fileContentStream = System.IO.File.Open(srcFilePath, System.IO.FileMode.Open))
{
var uploadSession = await graphClient.Me.Drive.Root.ItemWithPath(fileName).CreateUploadSession().Request().PostAsync();
var maxChunkSize = 5 * 1024 * 1024;
var provider = new ChunkedUploadProvider(uploadSession, graphClient, fileContentStream, maxChunkSize);
var chunkRequests = provider.GetUploadChunkRequests();
var readBuffer = new byte[maxChunkSize];
var trackedExceptions = new List<Exception>();
Microsoft.Graph.DriveItem itemResult = null;
foreach (var request in chunkRequests)
{
var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, trackedExceptions);
if (result.UploadSucceeded)
{
itemResult = result.ItemResponse;
}
}
}
}
catch (Microsoft.Graph.ServiceException e)
{
}
catch (Exception ex)
{
}
Run Code Online (Sandbox Code Playgroud)
上面的代码适用于普通文件名。但是,当我尝试上传名称为Test#123.pdf的文件时,“未将对象引用设置为对象”异常在行中引发var provider = new ChunkedUploadProvider(uploadSession, graphClient, fileContentStream, maxChunkSize);请参见下面的屏幕截图:
这是 OneDrive SDK 的限制,还是我没有正确传递参数?
| 归档时间: |
|
| 查看次数: |
336 次 |
| 最近记录: |