In last article, we tried to download single blob file from azure storage using Azure.Storage.Blobs. This is the new library developed by Microsoft to replace depercated Microsoft.WindowsAzure.Storage. So let's get started.
0. Setting up the context
In this article, we will try to get all the blobs(images) stored on Azure blob storage in defined format i.e. User_id/image.ext.
john_doe/image1.jpg
john_doe/profile.png
jane_doe/profile.PNG
So if there are blobs with given name in Azue, we are trying to get all blobs for user id john_doe
1. Install NuGet package
Install NuGet package Azure.Storage.Blobs. At the time of writing this, the latest version is 12.8.0.
2. Import library
using Azure.Storage.Blobs;
3. Get connection string
I assume you have Azure account and thus connection string to connect to Azure Blob Storage. Store this in a variable or constant based on your need.
const string CONN_STRING = <connection_string_from_azure_portal>
const string BLOB_CONTAINER = <blob_container_name>
-1. Now the final thing
I will list all blobs(images) present in given container and have specified format.
string userId = "john_doe";
var allBlobs = container.GetBlobs(prefix: $"{userId}");
The above code will fetch all the blobs details present in container with given prefix(john_doe).
If you want to download the blobs as well, this article might be helpful.
That's it. I hope this will be helpful. 🙂
Top comments (0)