使用Microsoft Graph SDK的OneDrive复制项-如果〜> 38mb文件,则在10秒后显示GatewayTimeout [英] OneDrive Copy Item using Microsoft Graph SDK - GatewayTimeout at 10 seconds if ~>38mb file
问题描述
我正在使用MS Graph .net SDK.尝试将共享点文档库复制到另一个共享点文档库.
I am using the MS Graph .net SDK. Attempting to copy a sharepoint document library to another sharepoint document library.
如果文件大小约为38mb,则会因未知错误而引发GatewayTimeout异常.
If the file is approximately 38mb, a GatewayTimeout exception is thrown for an unknown error.
MS出现错误,或者我做错了什么.这是我的代码:
Either MS has a bug, or I am doing something incorrectly. Here is my code:
HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Post, request.RequestUrl);
hrm.Content = new StringContent(JsonConvert.SerializeObject(request.RequestBody), System.Text.Encoding.UTF8, "application/json");
await client.AuthenticationProvider.AuthenticateRequestAsync(hrm);
HttpResponseMessage response = await client.HttpProvider.SendAsync(hrm);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
}
}
catch (Microsoft.Graph.ServiceException ex)
{
throw new Exception("Unknown Error");
}
有人在这里看到问题吗?
Anyone see a problem here?
这是我的修改代码
public static async Task copyFile(Microsoft.Graph.GraphServiceClient client, string SourceDriveId, string SourceItemId, string DestinationDriveId, string DestinationFolderId, string FileName)
{
try
{
var destRef = new Microsoft.Graph.ItemReference()
{
DriveId = DestinationDriveId,
Id = DestinationFolderId
};
await client.Drives[SourceDriveId].Items[SourceItemId].Copy(null, destRef).Request().PostAsync();
//await client.Drives[SourceDriveId].Root.ItemWithPath(itemFileName).Copy(parentReference: dest).Request().PostAsync();
}
catch (Microsoft.Graph.ServiceException ex)
{
throw new Exception(ex.Message);
}
}
以上修改后的代码继续出现相同的错误;但是,今晚,它也发生在以前运行良好的13.8mb文件中.
The above revised code continues to give the same error; however, tonight, it is also occurring on a 13.8mb file that previously had worked fine.
从逻辑上讲,因为较小的文件不会发生该错误,所以我认为这与文件大小有关.
Logically, because the error doesn't occur for smaller files, I think it has something to do with file size.
响应应该是带有位置标头的202.请参见在图形文档中复制项目;但是,我从未能够获得位置标头.我怀疑Microsoft Graph没有从OneDrive API获取位置标头信息,因此引发了网关超时错误.
The response is supposed to be a 202 with location header. See Copy Item in Graph Docs; however, I have never been able to obtain a location header. I suspect that Microsoft Graph is not getting the location header information from the OneDrive API and is therefore throwing a Gateway Timeout error.
推荐答案
我相信这是您要寻找的:
I believe this is what you're looking for:
await graphClient.Drives["sourceDriveId"]
.Items["sourceItemId"]
.Copy(null, new ItemReference()
{
DriveId = "destinationDriveId",
Id = "destinationFolderId"
})
.Request()
.PostAsync();
这将使用给定的DriveItem
并将其复制到另一个Drive
中的文件夹中.
This will take a given DriveItem
and copy it to a folder in another Drive
.
这篇关于使用Microsoft Graph SDK的OneDrive复制项-如果〜> 38mb文件,则在10秒后显示GatewayTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!