Eugene D. Gubenkov
Eugene D. Gubenkov

Reputation: 5357

How to find Azure Storage Blob by name suffix without enumerating whole container?

Having big amount of blobs inside Azure virtual directories:

VirtualDirectory1/file1
VirtualDirectory1/file2
...
VirtualDirectory1/fileN
...
VirtualDirectoryK/file1
VirtualDirectoryK/file2
...
VirtualDirectoryK/fileM

I need a fast way to find all blobs that ends with the certain suffix (for instance "file1"). As to prefixes there is a way to fetch only blobs that starts with some name:

blobContainer.ListBlobs(prefix: "prefixHere")

The following approach to fetch blobs with certain suffix results in fetching the full container and its filtering on the client.

var blobsFound =
    blobContainer
    .ListBlobs(useFlatBlobListing: true)
    .OfType<ICloudBlob>()
    .Where(b => b.Name.EndsWith("file1"))
    .ToList();

It could be clearly seen using Fiddler to capture traffic:

fiddler output

Is there a way to find all blobs by the suffix on the Azure side, without fetching full list of blobs to the client?

Upvotes: 5

Views: 5338

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136366

Is there a way to find all blobs by the suffix on the Azure side, without fetching full list of blobs to the client?

Unfortunately no. Blob service only supports filtering by blob prefix and not by suffix. Your only option would be to list blobs and then do client side filtering.

Upvotes: 3

Related Questions