Reputation: 1187
I have following Azure blobs inside a container,
111_101.jpg
111_102.jpg
111_103.jpg
112_204.jpg
112_205.jpg
Now I know the first part of the image name, that is 111 or 112. Is it possible for me to take the first Image which starts from 111 or 112. ?
How can I modify the following code, when variable _image will have only the first part of the file name, that is 111.
string _urlContainer = containerName;
string _image = "111_102.jpg";
CloudBlobClient blobClient = null;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(_urlContainer);
CloudBlockBlob blockBlob = container.GetBlockBlobReference(_image);
if (Exists(blockBlob))
{
return blockBlob.DownloadByteArray();
}
Upvotes: 2
Views: 4263
Reputation:
Short answer: no.
Long answer:
If you don't know the blob name, you have to get all blob references with container.ListBlobs()
and then find the one, you're lokking for.
To reduce the overhead, you could use virtual directory. Name your blobs
111/101.jpg
111/102.jpg
111/103.jpg
112/204.jpg
112/205.jpg
Note on comment from Gaurav Mantri: it is not necessary to substitute the underscores with slashes, however I believe, that the SDKs offers methods, to work with slashes. (And maybe they have some internal optimizations, that can work more efficiently with slashes)
And you can list your blobs with container.ListBlobs("111/", true);
The function will only return those blobs:
111/101.jpg
111/102.jpg
111/103.jpg
And from that result, you can take the first one.
Upvotes: 4