I want to upload large Files to Azure Blob Storage (500-2000MB) and I try to do this with the following code:
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
};
}
I instantly get the following message:
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.)
If i remove the InitialTransferSize
from the StorageTransferOptions
, i get the following error after some time:
retry failed after 6 tries. (The operation was canceled.)
As far as I understood the new SDK, the upload in chunks and therefore the whole handling of the blockIds etc. should be done by the SDK. Or am I wrong?
Does anybody know why this is not working? I did not find anything different then this for BlobContainerClient, only for the old cloudblobcontainer.
Update: Some Additional Informations:
It is a .netCore 3.1 Application which runs with the library Topshelf as a Windows Service
I was not able to get it working with version 12.6.0...
I downgraded to Microsoft.Azure.Storage.Blob v11 and implemented the upload based on this thread https://stackoverflow.com/a/58741171/765766
This works fine for me now