2017-06-19 12 views
1

我正在使用Microsoft Graph SDK在OneDrive中以塊的形式上載文件。我正在使用以下代碼上傳文件: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) 
{ 
} 

上述代碼可以正常使用文件名。然而,當我試圖上傳與名稱的文件測試#123.pdf,「對象未設置爲一個對象」異常在行var provider = new ChunkedUploadProvider(uploadSession, graphClient, fileContentStream, maxChunkSize);拋出請看下面的截圖:enter image description here

這是一個限制OneDrive SDK,或者我沒有正確傳遞參數?

回答

3

#號在URL中有特殊含義。在你使用它之前,你需要URL編碼文件名:Test%23123.pdf

相關問題