I am trying to upload a file (~250Mb size) to Azure File Shares (not blob storage) and the upload fails after multiple retry attempts and throws and exception saying that the request failed after 6 retries. I faced this exact same problem with uploading files to the azure blob storage and I found out that I needed to reduce the number of concurrent threads on BlobUploadOptions since my network speed could not handle a large number of parallel threads for upload. Now for uploading to Azure File Shares, I am not able to find the property where I can set the number of maximum concurrency for upload. Any ideas about how I can set that? Or any alternate solutions? P.S. I'm using .NET Azure SDK v12
The code I'm using:
string shareName = "test-share";
string dirName = "sample-dir";
string fileName = Path.GetFileName(localFilePath);
ShareClient share = new ShareClient(ConnectionString, shareName);
await share.CreateAsync();
ShareDirectoryClient directory = share.GetDirectoryClient(dirName);
await directory.CreateAsync();
ShareFileClient fileClient = directory.GetFileClient(fileName);
using (FileStream stream = File.OpenRead(localFilePath))
{
await fileClient.CreateAsync(stream.Length);
await fileClient.UploadRangeAsync(
new HttpRange(0, stream.Length),
stream);
}
I had solved the problem while uploading to blob storage like this:
BlobUploadOptions uploadOptions = new BlobUploadOptions() {
TransferOptions = new Azure.Storage.StorageTransferOptions() {
MaximumConcurrency = 2,
InitialTransferSize = 100 * 1024 * 1024
}
};
using (FileStream uploadFileStream = File.OpenRead(filePath))
{
await blobClient.UploadAsync(uploadFileStream, uploadOptions);
uploadFileStream.Close();
}