C# &引用;超过最大请求长度";将文件上载到Onedrive时
我正在使用“OneDriveApiBrowser”中的示例代码作为向我的应用程序添加“保存到一个驱动器”支持的基础。这利用了Microsoft.Graph,我可以上传小文件,但较大的文件(10Mb)不会上传,并给出一个错误“超过最大请求长度”。我的应用程序和示例代码中都出现了相同的错误,代码行如下:C# &引用;超过最大请求长度";将文件上载到Onedrive时,c#,onedrive,C#,Onedrive,我正在使用“OneDriveApiBrowser”中的示例代码作为向我的应用程序添加“保存到一个驱动器”支持的基础。这利用了Microsoft.Graph,我可以上传小文件,但较大的文件(10Mb)不会上传,并给出一个错误“超过最大请求长度”。我的应用程序和示例代码中都出现了相同的错误,代码行如下: DriveItem uploadedItem = await graphClient.Drive.Root.ItemWithPath(drivePath).Content.Request().Put
DriveItem uploadedItem = await graphClient.Drive.Root.ItemWithPath(drivePath).Content.Request().PutAsync<DriveItem>(newStream);
DriveItem uploadedItem=wait graphClient.Drive.Root.ItemWithPath(drivePath.Content.Request().PutAsync(newStream);
有没有办法增加可上传文件的最大大小?如果是这样的话,怎么办?Graph只接受使用PUT-to-content的小文件,所以您需要查看。因为您使用的是Graph SDK,所以我会使用它 下面是一些完整的代码-它不会直接编译,但应该让您看到所涉及的步骤:
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;
}
}
var uploadSession=wait graphClient.Drive.Root.ItemWithPath(“filename.txt”).CreateUploadSession().Request().PostAsync();
var maxChunkSize=320*1024;//320 KB-将其更改为块大小。5MB是默认值。
var provider=new ChunkedUploadProvider(上传会话、graphClient、inputStream、maxChunkSize);
//设置块请求的必要性
var chunkRequests=provider.GetUploadChunkRequests();
var readBuffer=新字节[maxChunkSize];
var trackedExceptions=新列表();
DriveItemResult=null;
//上传区块
foreach(chunkRequests中的var请求)
{
var result=await provider.GetChunkRequestResponseAsync(请求、读取缓冲区、跟踪异常);
if(result.uploadsuccessed)
{
itemResult=result.ItemResponse;
}
}