Checking for an item in an Azure blob container is done forever (SDK 2.0)

I am updating my C # solution to use the new Azure SDK 2.0 libraries. I made minor changes to accounting for breaking changes in libraries 2.0, but other than that, this is the same code. I tested against my local storage and everything works fine, but when I test the storage with Azure storage, it takes too long to check if the blob element exists. It literally takes a minute, if not more, to simply return a boolean value indicating whether the element exists or not.

In the code example below, a line that takes a very long time should be "if (! Blob.Exists ())".

public byte[] GetBlobContent(string blobName) { if (blobName == "") return null; var blobClient = _storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(_containerName); var blob = container.GetBlockBlobReference(blobName); if (!blob.Exists()) { return null; } byte[] buffer; using (var ms = new MemoryStream()) { blob.DownloadToStream(ms); buffer = ms.ToArray(); } return buffer; } 

Are there any additional changes I need to make to my code to make it work the way it was used?

+4
source share
2 answers

An alternative approach would be to skip the Exists () check and just let the DownloadToStream program crash if the blob does not exist. You will need a try / catch block around DownloadToStream to handle the "expected" failure. This approach saves you round trip for each blob read, as it should only delete once once, not twice.

0
source

Fiddler does not reveal anything. I had a similar problem when the process hung indefinitely until a timeout occurred. Try replacing the calls with CloudTable.CreateIfNotExists with CloudTable.CreateIfNotExistsAsync and call CloudTable.Execute with CloudTable.ExecuteAsync .

Unfortunately, I cannot say why this works. During recording, the WindowsAzure.Storage-PremiumTable package was in pre-release mode and was allegedly mistaken.

0
source

All Articles