【问题标题】:"maximum request length exceeded" When uploading a file to Onedrive“超出最大请求长度”将文件上传到 Onedrive 时
【发布时间】:2017-05-15 08:07:52
【问题描述】:

我使用“OneDriveApiBrowser”中的示例代码作为基础,为我的应用添加保存到一个驱动器的支持。这利用了 Microsoft.Graph,我可以上传小文件,但较大的文件 (10Mb) 不会上传并给出错误“超出最大请求长度”。我在我的应用程序和示例代码中都遇到了同样的错误,代码如下:

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

有没有办法增加可以上传的文件的最大大小?如果有怎么办?

【问题讨论】:

    标签: c# onedrive


    【解决方案1】:

    Graph 仅接受使用 PUT-to-content 的小文件,因此您需要查看 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 2011-04-20
      相关资源
      最近更新 更多