[英]Microsoft Graph HttpProvider Error on File Upload
I have a PDF I need to upload to a SharePoint Document Library using Microsoft Graph.我有一个 PDF 我需要使用 Microsoft Graph 上传到 SharePoint 文档库。 My code has successfully done this for months, until it stopped working April 17 with seemingly no change to our SharePoint and certainly not my code.
我的代码已经成功完成了几个月,直到它在 4 月 17 日停止工作,我们的 SharePoint 似乎没有任何变化,当然也不是我的代码。
I have a function that performs the upload:我有一个执行上传的 function:
public static async Task<DriveItem> UploadLargeFile(string localFilePath, string spPath)
{
DriveItem uploadedFile = null;
using (Stream fileStream = System.IO.File.OpenRead(localFilePath))
{
UploadSession uploadSession = await GraphAPIConnection.GraphClient.Sites[siteid].Drives[driveid].Root.ItemWithPath(spPath).CreateUploadSession().Request().PostAsync();
List<Exception> exceptions = new List<Exception>();
if (uploadSession != null)
{
//Chunk size must be divisible by 320KiB, our chunk size will be slightly more than 1MB
int maxSizeChunk = (320 * 1024) * 4;
ChunkedUploadProvider uploadProvider = new ChunkedUploadProvider(uploadSession, GraphAPIConnection.GraphClient, fileStream, maxSizeChunk);
IEnumerable<UploadChunkRequest> chunkRequests = uploadProvider.GetUploadChunkRequests();
byte[] readBuffer = new byte[maxSizeChunk];
//Using one session, upload each chunk of the file individually
foreach (UploadChunkRequest request in chunkRequests)
{
try
{
UploadChunkResult result = await uploadProvider.GetChunkRequestResponseAsync(request, readBuffer, exceptions);
if (result.UploadSucceeded)
{
uploadedFile = result.ItemResponse;
}
}
catch (Exception ex)
{
Debug.WriteLine("message: " + ex.Message + "\t\ttrace: " + ex.StackTrace);
}
}
}
}
return uploadedFile;
}
My catch produces the following output:我的捕获产生以下 output:
message: Code: generalException Message: An error occurred sending the request.
消息:代码:generalException 消息:发送请求时发生错误。 trace: at Microsoft.Graph.HttpProvider.d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.HttpProvider.d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.UploadChunkRequest.d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.UploadChunkRequest.d__16.MoveNext() --- End of stack trace from p
跟踪:在 Microsoft.Graph.HttpProvider.d__19.MoveNext() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime。 CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.HttpProvider.d__18.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在 Microsoft.Graph.UploadChunkRequest.d__17.MoveNext() --- 在 System.Runtime 中从先前引发异常的位置结束堆栈跟踪。 CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.UploadChunkRequest.d__16.MoveNext() --- 从 p 结束堆栈跟踪revious location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.ChunkedUploadProvider.d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at MyNameSpace.SharePointUploader.d__9.MoveNext() in MyDir\SharePointUploader.cs:line 173
抛出异常的过往位置 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.Graph.ChunkedUploadProvider.d__17.MoveNext() - -- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 System.Runtime.CompilerServices 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) .TaskAwaiter`1.GetResult() 在 MyNameSpace.SharePointUploader.d__9.MoveNext() 在 MyDir\SharePointUploader.cs:line 173
As you can see,如你看到的,
uploadProvider.GetChunkRequestResponseAsync(request, readBuffer, exceptions)
leads to the following that produces an error:导致以下产生错误:
at Microsoft.Graph.HttpProvider.d__19.MoveNext()
在 Microsoft.Graph.HttpProvider.d__19.MoveNext()
I've double checked that all of the inputs to the function appear valid;我仔细检查了 function 的所有输入是否有效; and again there have been no changes to the code in months.
几个月来,代码也没有任何变化。 I've tried a third party ETL software and was able to upload the PDF to the folder I wanted - that software is also built using Microsoft Graph.
我尝试了第三方 ETL 软件,并且能够将 PDF 上传到我想要的文件夹 - 该软件也是使用 Microsoft Graph 构建的。
Here is where I am stumped.这就是我难过的地方。 How can I further debug this to determine exactly why HttpProvider is throwing an error?
我如何进一步调试它以确定 HttpProvider 抛出错误的确切原因?
Found the fix to this.找到了解决方法。 Two part answer.
分两部分回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.