gpt4 book ai didi

c# - 创建 DriveItem 时为 "Error getting value from ReadTimeout"

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:36 24 4
gpt4 key购买 nike

我正在尝试使用 Microsoft Graph API 使用现有 DriveItem 的内容创建新的 SharePoint DriveItem。但是,在尝试创建 DriveItem 时出现以下错误。有人可以解释为什么吗?

编辑:简化为使用手动创建的 MemoryStream 对象

GraphServiceClient graphClient = GraphSDKHelper.GetAuthenticatedClient();
using (var docStream = new MemoryStream(1024))
{
var doc = new DriveItem
{
Content = docStream,
Name = "00_newDoc.docx",
ParentReference = new ItemReference
{
Id = "<folderId"
}
};
var resultItem = await graphClient.Drives["<driveId>"].Items["<folderId>"].Request().CreateAsync(driveItem);
}

我可以使用以下命令直接上传文件内容,但我无法通过一次调用在 DriveItem 中指定更多元数据。

var resultItem = await graphClient.Drives["<driveId>"].Items["<folderId>"].ItemWithPath("00_newDoc.docx").content.Request().PutAsync<DriveItem(docStream);

错误:

Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'.
at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer) at Microsoft.Graph.Serializer.SerializeObject(Object serializeableObject) at Microsoft.Graph.BaseRequest.d__36.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.BaseRequest.d__321.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.DriveItemRequest.<CreateAsync>d__2.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 Informa.eDocs.AzureFunctions.Functions.PostDocToSharePoint.d__0.MoveNext()

内部异常:

Timeouts are not supported on this stream. at System.IO.Stream.get_ReadTimeout() at GetReadTimeout(Object ) at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)

最佳答案

我不知道你遇到了什么问题。

话虽如此,下载文件流只是为了将其作为新的 driveitem 再次上传是否有理由?

您是否考虑过使用复制功能?它应该像这样工作(我还没有尝试过):

// Copy item reference
ItemReference iRef = new ItemReference()
{
DriveId = "b!ez3F6Nysf0yYklsI2gUdcx4e7pSsSDZClwfWe3rFh4mSiYpAIn5zRLcsEeS7g5dr",
Id = "01YYVWN6F6Y2GOVW7725BZO354PWSELRRZ"
};

// Copy it
await graphClient.Me.Drives["<driveId>"].Items["<ItemId>"].Copy("copiedItem.txt", iRef).Request().PostAsync();

更新

API 不适合以这种方式使用。我不知道为什么它不能在一个电话中完成。我知道您必须首先使用 POST 创建项目(示例显示文件夹,但文件的想法是相同的),然后是 PUT后续调用中的内容流。

关于c# - 创建 DriveItem 时为 "Error getting value from ReadTimeout",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47539979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com