I have an application that upload, download and delete files on Azure blob storage. It works fine but when I perform load testing sometimes I got following exception during file download.
Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
I am initializing these things once in constructor and then reuse it for all methods:
cloudStorageAccount = CloudStorageAccount.Parse(_storage.ConnectionString);
blobClient = cloudStorageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference(_storage.Container);
var permission = container.GetPermissions();
permission.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permission);
Here is my code for blob download:
MemoryStream memoryStream = new MemoryStream();
var retryPolicy = TransientFactory.GetStorageRetryPolicy();
retryPolicy.ExecuteAction(() =>
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(sourceUri);
if (blockBlob.Exists())
{
blockBlob.DownloadToStream(memoryStream);
memoryStream.Position = 0;
}
});
return memoryStream;