Ill*_*lep 2 c# azure azure-blob-storage
以下代码演示了将文件上传到 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);
Run Code Online (Sandbox Code Playgroud)
请尝试如下操作:
//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()
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2233 次 |
| 最近记录: |