gpt4 book ai didi

c# - 显示 Azure BLOB 的上传进度

转载 作者:行者123 更新时间:2023-12-02 23:12:36 28 4
gpt4 key购买 nike

以下代码演示了将文件上传到 Azure BLOB。因此,我将上传较大的文件,因此存在由于带宽问题导致上传失败的风险(在 SO 中讨论)。

以下代码工作正常,但我需要一种方法以百分比 % 的形式向最终用户显示上传进度。我如何修改我的代码以使其成为可能?

BlobUploadOptions op = new BlobUploadOptions
{
TransferOptions = new StorageTransferOptions
{
MaximumTransferSize = 4 * 1024 * 1024,
InitialTransferSize = 4 * 1024 * 1024,
MaximumConcurrency= 5
},
HttpHeaders = new BlobHttpHeaders
{
ContentType = request.Request.ContentType
}
};

Azure.Response<BlobContentInfo> ci = await
blobClient.UploadAsync(fileStream, op);

最佳答案

请尝试以下操作:

//Define a progress handler.
class MyProgressHandler : IProgress<long>
{
public void Report(long value)
{
//Do something to report the progress. I am simply printing the bytes uploaded.
Console.WriteLine($"Bytes uploaded: {value}");
}
}

//Use the progress handler in your upload options.
BlobUploadOptions op = new BlobUploadOptions
{
TransferOptions = new StorageTransferOptions
{
MaximumTransferSize = 4 * 1024 * 1024,
InitialTransferSize = 4 * 1024 * 1024,
MaximumConcurrency= 5
},
HttpHeaders = new BlobHttpHeaders
{
ContentType = request.Request.ContentType
},
ProgressHandler = new MyProgressHandler()
};

关于c# - 显示 Azure BLOB 的上传进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67817675/

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