使用OneDrive SDK上传大文件时如何提高速度

How to improve speed when uploading large files using OneDrive SDK

使用OneDrive SDK上传大文件附件时,速度太慢

根据 1GB 的文件,大约需要 45 分钟到 1 小时。

有什么方法可以改善这个问题吗?

public async Task<JObject> UploadLargeFiles(string upn, IFormFile files)
    {
        var jObject = new JObject();
        int fileSize = Convert.ToInt32(files.Length);
        var fileStream = files.OpenReadStream();

        GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

        var uploadProps = new DriveItemUploadableProperties
        {
            ODataType = null,
            AdditionalData = new Dictionary<string, object>
            {
                { "@microsoft.graph.conflictBehavior", "rename" }
            }
        };

        var item = this.SelectUploadFolderID(upn).Result;
        var uploadSession = await client.Users[upn].Drive.Items[item].ItemWithPath(files.FileName).CreateUploadSession(uploadProps).Request().PostAsync();

        int maxChunkSize = 320 * 1024;
        var uploadTask = new LargeFileUploadTask<DriveItem>(uploadSession, fileStream, maxChunkSize);

        var response = await uploadTask.UploadAsync();

        if (response.UploadSucceeded)
        {
            jObject = JObject.FromObject(new { result = "success"});
            return jObject;
        }
        else
        {
            return null;
        }
    }

我已遵循 blogpost and it worked for me. I know uploading bigger files may take a while, give a fact that it depends on the internet speed, so i will exclude Graph API out of the picture here. Apart from that i dont see any options to speedup. Also you can consider filing uservoice 中提供的 examples/guidance。