在 OneDrive 中上传文件时未将对象引用设置为对象

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 的限制,还是我没有正确传递参数?

Mar*_*eur 5

# 符号在 URL 中具有特殊含义。在使用它之前,您需要对文件名进行 URL 编码:Test%23123.pdf.