【发布时间】:2020-12-28 07:04:34
【问题描述】:
我想将大文件上传到 Azure Blob 存储 (500-2000MB),我尝试使用以下代码执行此操作:
private BlobContainerClient containerClient;
public async Task<UploadResultDto> Upload(FileInfo fileInfo, string remotePath)
{
try
{
var blobClient = containerClient.GetBlobClient(remotePath + "/" + fileInfo.Name);
var transferOptions = new StorageTransferOptions
{
MaximumConcurrency = 1,
MaximumTransferSize = 10485760,
InitialTransferSize = 10485760
};
await using var uploadFileStream = File.OpenRead(fileInfo.FullName);
await blobClient.UploadAsync(uploadFileStream, transferOptions: transferOptions);
uploadFileStream.Close();
return new UploadResultDto()
{
UploadSuccessfull = true
};
}
catch (Exception ex)
{
Log.Error(ex,$"Error while uploading File {fileInfo.FullName}");
}
return new UploadResultDto()
{
UploadSuccessfull = false
};
}
我立即收到以下消息:
The specified blob or block content is invalid.
RequestId:c5c2d925-701e-0035-7ce0-8691a6000000
Time:2020-09-09T19:33:40.9559646Z
Status: 400 (The specified blob or block content is invalid.)
如果我从StorageTransferOptions 中删除InitialTransferSize,一段时间后我会收到以下错误:
retry failed after 6 tries. (The operation was canceled.)
据我了解,新 SDK 的分块上传以及 blockIds 等的整个处理都应该由 SDK 完成。还是我错了?
有人知道为什么这不起作用吗?对于 BlobContainerClient,我没有发现任何与此不同的地方,仅适用于旧的 cloudblobcontainer。
更新: 一些附加信息:
这是一个 .netCore 3.1 应用程序,与库 Topshelf 作为 Windows 服务一起运行
【问题讨论】:
-
这是什么?
await using var uploadFileStream = File.OpenRead(fileInfo.FullName);这是我不知道的 C# 中的一些新东西吗? -
哇好甜。感谢您的信息。
-
我遇到了“重试 6 次后重试失败。任务已取消。”尝试将 3GB Azure SQL 数据库导出到 Azure 存储。工作了很多年,直到这个月都没有问题。
标签: c# azure .net-core azure-blob-storage topshelf