使用 Microsoft Graph SDK 的 OneDrive 复制项目 - 如果 ~>38mb 文件,GatewayTimeout 为 10 秒 [英] OneDrive Copy Item using Microsoft Graph SDK - GatewayTimeout at 10 seconds if ~>38mb file

查看:17
本文介绍了使用 Microsoft Graph SDK 的 OneDrive 复制项目 - 如果 ~>38mb 文件,GatewayTimeout 为 10 秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.请参阅 在 Graph Docs 中复制项目;但是,我从未能够获得位置标头.我怀疑 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 文件,GatewayTimeout 为 10 秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆