2017-05-15 76 views
0

我使用「OneDriveApiBrowser」示例代碼作爲添加保存到我的應用的一個驅動器支持的基礎。這使得使用Microsoft.Graph,我可以上傳小文件,但更大的文件(10Mb)不會上傳,並給出錯誤「超過最大請求長度」。我得到了我的兩個應用程序相同的錯誤,並與下面的代碼示例代碼:「超出最大請求長度」上傳文件到Onedrive

DriveItem uploadedItem = await graphClient.Drive.Root.ItemWithPath(drivePath).Content.Request().PutAsync<DriveItem>(newStream); 

是否有增加可上傳文件的最大尺寸的方法嗎?如果是這樣如何?

回答

1

圖表只接受使用PUT到內容的小文件,因此您需要查看creating an upload session。由於您使用Graph SDK,我會使用this test case as a guide

下面是完整一些代碼 - 它不會直接編譯,但它應該讓你看到涉及的步驟:

var uploadSession = await graphClient.Drive.Root.ItemWithPath("filename.txt").CreateUploadSession().Request().PostAsync(); 

var maxChunkSize = 320 * 1024; // 320 KB - Change this to your chunk size. 5MB is the default. 

var provider = new ChunkedUploadProvider(uploadSession, graphClient, inputStream, maxChunkSize); 

// Setup the chunk request necessities 
var chunkRequests = provider.GetUploadChunkRequests(); 
var readBuffer = new byte[maxChunkSize]; 
var trackedExceptions = new List<Exception>(); 

DriveItem itemResult = null; 

//upload the chunks 
foreach (var request in chunkRequests) 
{ 
    var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, trackedExceptions); 

    if (result.UploadSucceeded) 
    { 
     itemResult = result.ItemResponse; 
    } 
} 
+0

謝謝布拉德,這解決了我的問題。 –

相關問題