Microsoft graph api 在OneDrive中上载文件时,对象引用未设置为对象

Microsoft graph api 在OneDrive中上载文件时,对象引用未设置为对象,microsoft-graph-api,onedrive,Microsoft Graph Api,Onedrive,我正在使用Microsoft Graph SDK将文件分块上传到OneDrive中。我正在使用以下代码上载文件: try { GraphServiceClient graphClient = this.GetGraphServiceClient(accessToken); string fileName = Path.GetFileName(srcFilePath); using (var fileContentStream = System.IO.File.Open

我正在使用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)
{ 
}
试试看
{
GraphServiceClient graphClient=this.GetGraphServiceClient(accessToken);
字符串fileName=Path.GetFileName(srcFilePath);
使用(var fileContentStream=System.IO.File.Open(srcFilePath,System.IO.FileMode.Open))
{
var uploadSession=wait graphClient.Me.Drive.Root.ItemWithPath(文件名).CreateUploadSession().Request().PostAsync();
var maxChunkSize=5*1024*1024;
var provider=new ChunkedUploadProvider(上传会话、graphClient、fileContentStream、maxChunkSize);
var chunkRequests=provider.GetUploadChunkRequests();
var readBuffer=新字节[maxChunkSize];
var trackedExceptions=新列表();
Microsoft.Graph.DriveItem itemResult=null;
foreach(chunkRequests中的var请求)
{
var result=await provider.GetChunkRequestResponseAsync(请求、读取缓冲区、跟踪异常);
if(result.uploadsuccessed)
{
itemResult=result.ItemResponse;
}
}
}
}
捕获(Microsoft.Graph.ServiceException e)
{
}
捕获(例外情况除外)
{ 
}
以上代码适用于普通文件名。但是,当我尝试上载名为Test#123.pdf的文件时,在
var provider=new ChunkedUploadProvider(uploadSession,graphClient,fileContentStream,maxChunkSize)行抛出“对象引用未设置为对象”异常请参见下面的屏幕截图:

这是OneDrive SDK的限制,还是我没有正确传递参数?

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

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