简体   繁体   中英

Given N containers find the blob

We have a setup where a given uuid tagged blob could be in one of N containers or none.

What is the best way to check all containers in parallel returning the blob if found or reporting blob doesn't exist?

Our container names are dates and there won't be more than five at any given time there will only be one blob.

You can use CloudBlob.FetchAttributes() which does a HEAD on the blob and will throw an exception if it fails. (essentially testing if exists)

So just create your container & blob handles in a loop, test if exists, and return if true.

public static class BlobExtensions
{
    public static bool Exists(this CloudBlob blob)
    {
        try
        {
            blob.FetchAttributes();
            return true;
        }
        catch (StorageClientException e)
        {
            if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
            {
                return false;
            }
            else
            {
                throw;
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM