Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Support `deferCommit` in `LargeFileUploadTask` for upload sessions

未关闭
#984 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp

调研方向

从 src/Microsoft.Graph.Core/Tasks/LargeFileUploadTask.cs 开始,重点查看 UploadAsync、UpdateSessionStatusAsync 和现有的 DeleteSessionAsync 方法。阅读链接的 Microsoft Learn 上传会话文档,并确定应如何表示延迟提交。当延迟上传在发送完所有字节后停止,并提供一种无需耗尽重试次数即可显式完成会话的方式时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

type:feature

I want to defer the final creation of the file being uploaded via an upload session in the destination (in this case, SharePoint Embedded) until I explicitly make a request to complete the upload. For this, I'm setting the deferCommit property in the request arguments for the creation of the upload session, as indicated in Create an upload session - driveItem: createUploadSession | MS Learn.

When using LargeFileUploadTask to use the created upload session, as indicated in Upload large files using the Microsoft Graph SDKs | MS Learn, the upload task does not stop when all the bytes have been uploaded and the server returns that there are no nextExpectedRanges in the 202 response. It starts a loop to retrieve the status of the upload session and the expected ranges (which in return are empty) until all retry attempts have been exhausted. Then, it throws an exception saying Upload failed too many times..

From source: LargeFileUploadTask.cs

public async Task<UploadResult<T>> UploadAsync(IProgress<long> progress = null, int maxTries = 3, CancellationToken cancellationToken = default)
{
    var uploadTries = 0;
    var trackedExceptions = new List<Exception>();

    while (uploadTries < maxTries)
    {
        var sliceRequests = this.GetUploadSliceRequests();

        foreach (var request in sliceRequests)
        {
            var uploadResult = await this.UploadSliceAsync(request, trackedExceptions, cancellationToken).ConfigureAwait(false);

            progress?.Report(request.RangeEnd);//report the progress of upload (how many bytes have been uploaded so far)

            if (uploadResult.UploadSucceeded) // **<--- from observation/testing: this is always false**
            {
                return uploadResult;
            }

            ThrowIfUploadCancelled(trackedExceptions, cancellationToken);
        }

        await this.UpdateSessionStatusAsync(cancellationToken).ConfigureAwait(false);
        uploadTries += 1;
        if (uploadTries < maxTries)
        {
            // Exponential back off in case of failures.
            await Task.Delay(2000 * uploadTries * uploadTries, cancellationToken).ConfigureAwait(false);
        }

        ThrowIfUploadCancelled(trackedExceptions, cancellationToken);
    }

    throw new TaskCanceledException("Upload failed too many times. See InnerException for list of exceptions that occured.", new AggregateException(trackedExceptions.ToArray()));
}

public async Task<IUploadSession> UpdateSessionStatusAsync(CancellationToken cancellationToken = default)
{
    var requestBuilder = new UploadSessionRequestBuilder(this.Session, this._requestAdapter);
    var newSession = await requestBuilder.GetAsync(cancellationToken).ConfigureAwait(false);

    var newRangesRemaining = this.GetRangesRemaining(newSession);  // **<--- from observation/testing: this return empty**

    this._rangesRemaining = newRangesRemaining;
    newSession.UploadUrl = this.Session.UploadUrl; // Sometimes the UploadUrl is not returned
    this.Session = newSession;
    return newSession;
}
Proposed solution

I would like LargeFileUploadTask to handle defer commits. Alternatives:

  1. Allow the caller to indicate that the upload is deferred during construction (i.e.: a parameter).
  2. The task itself can interpret the 202 response with no next expected ranges as having the commit deferred.

Once the task is done uploading, there could be a CommitSessionAsync method (in the same line as the DeleteSessionAsync method) to perform the commit request.

主要语言
C#
星标
163
派生
65
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoftgraph/msgraph-sdk-dotnet-core 的其他 Issue

查看 microsoftgraph/msgraph-sdk-dotnet-core 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。