简体   繁体   中英

Find all blobs with prepend in Azure Blob Storage

We use Azure's .NET Core SDK for blob storage to get and update static blobs, and I want to be able to find all blobs in a specific directory prepended with a certain string of characters.

I can find individual items using something like:

string fileName = "c999iconFile.png";

var blob = _myDirectory.GetBlobReference(fileName);

But I can't seem to be able to find a way to find all blobs prepended with something like c999 .

We're looking to find a list of blobs that match a certain prepend and then make a mass delete on them.

The brute force solution is to iterate through one-by-one and do it but that seems wasteful.

Is there a way to achieve this?

But I can't seem to be able to find a way to find all blobs prepended with something like c999.

You can perform a prefix based search where the storage service returns you a list of blobs names of which starts with a certain prefix ("c999" in your case).

var blobs = blobContainerClient.GetBlobs(traits = Azure.Storage.Blobs.Models.BlobTraits.None, states = Azure.Storage.Blobs.Models.BlobStates.None, string prefix = "c999");

Reference: BlobContainerClient.GetBlobs

Above code is for SDK v12. If you're using an older version of the library, here's the code that you would use:

var blobs = blobContainer.ListBlobs(prefix = "c999", bool useFlatBlobListing = true);

Reference: CloudBlobContainer.ListBlobs

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