c# - 位置未知,将文件上传到 Sharepoint 时使用 Microsoft Graph API 时出现问题
问题描述
将文件上传到共享点时遇到错误,
处理请求时发生未处理的异常。AggregateException:发生一个或多个错误。未知位置 TaskCanceledException:上传失败太多次。有关发生的异常列表,请参阅 InnerException。Microsoft.Graph.LargeFileUploadTask.UploadAsync(IProgress 进度,int maxTries)
using (FileStream fileStream = System.IO.File.OpenRead(filePath))
{
// Use properties to specify the conflict behavior
// in this case, replace
var uploadProps = new DriveItemUploadableProperties
{
ODataType = null,
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" }
}
};
var uploadSession = await _graphServiceClient.Drives["b!G_sdavHlaEmqc9oVvd2b-WJ1ylhoxrtPt9v6xJPy1RQH5vGZK44uQau0-P9QCo5r"]
.Root
.ItemWithPath(file.FileName)
.CreateUploadSession(uploadProps)
.Request()
.PostAsync();
// Max slice size must be a multiple of 320 KiB
int maxSliceSize = 320 * 1024;
var fileUploadTask =
new LargeFileUploadTask<DriveItem>(uploadSession, fileStream, maxSliceSize);
// Create a callback that is invoked after each slice is uploaded
IProgress<long> progress = new Progress<long>(prog => {
Console.WriteLine($"Uploaded {prog} bytes of {fileStream.Length} bytes");
});
try
{
// Upload the file
var uploadResult = await fileUploadTask.UploadAsync(progress);
if (uploadResult.UploadSucceeded)
{
// The ItemResponse object in the result represents the
// created item.
Console.WriteLine($"Upload complete, item ID: {uploadResult.ItemResponse.Id}");
}
else
{
Console.WriteLine("Upload failed");
}
}
catch (ServiceException ex)
{
Console.WriteLine($"Error uploading: {ex.ToString()}");
}
}
但我们看到
Creaste ~tmp95_Manipulador de Alimentos GUERO...pdf en ex3 Hace un minuto
在我们尝试存储的共享点文件夹上,这意味着在该文件夹上创建了一些临时文件,但不是最终文件
关于这个问题的任何线索?
解决方案
推荐阅读
- cygwin - 无法让 cygwin 忽略 ZSH 中的回车
- ssl - 如何重现成功的 openssl_verify
- javascript - javascript生成的CSS类不应用样式
- node.js - 使用 mongodb atlas 的跨域请求阻止了 Node Js
- excel - 尝试将列中的单元格与数组进行比较,如果不匹配则隐藏单元格的行
- garrys-mod - Sending object through http.Post() not working
- javascript - 域感知反应路由器
- html - HTML解析器到csv,输出文件夹中没有结果
- html - Bootstrap 4如何使用css通过清除按钮颜色更改来更改输入搜索
- selenium - Selenium, Robot framework 使用这个我们必须点击下面描述的按钮