0
votes

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;
3
You don't indicate how sourceUri is set. Is it possible that's getting a bad address?MikeWo
I am storing blob name in database and then passing same name for blob download. Note that sourceUri is a blob name.Jamil
Azure Blob Storage names are case sensitive. Have you checked that the case is correct on the blobs that are failing to download? (I would expect the 'Exists' method to perform this check itself of course).The Senator

3 Answers

1
votes

Make sure that the name of the file - which is a part of the URL - has EXACT same casing - Do not use .ToLower() etc to change the casing.

Atleast this was the issue in my case.

0
votes

If you are using Azure Storage Client Library 4.0 or above, please pass in the blob name instead of a Uri to GetBlockBlobReference. Or if you would like to use a Uri, you should use the CloudBlockBlob constructor instead.

0
votes

Also check if the file is not uploaded to a sub Folder. In such case you'll need to add the name of this sub Folder in your Blob reference :

        CloudBlockBlob blob = container.GetBlockBlobReference("subFolder/"+reference);