The Ops Community ⚙️


Posted on

Get a list of all blobs in a specified Azure container

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.

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.

Enter fullscreen mode Exit fullscreen mode

So if there are blobs with given name in Azue, we are trying to get all blobs for user id b__kithmini

Install NuGet package

Install NuGet package Azure.Storage.Blobs. At the time of writing this, the latest version is 12.8.0.

Import library

using Azure.Storage.Blobs;

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>
Enter fullscreen mode Exit fullscreen mode

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}");
Enter fullscreen mode Exit fullscreen mode

The above code will fetch all the blobs details present in container with given prefix(b_kithmini).

I hope this will be helpful. 🙂

Top comments (0)