3

I've a java code where I list blobs and filter in for loop to fetch only files with a specific extension. Is there a way to query/request container to return just blobs with specific extension? I don't want to loop through all the blobs in the container to do this.

3 Answers 3

4

Is there a way to query/request container to return just blobs with specific extension?

Unfortunately no. You can't query blob storage to return blobs with a particular extension.

I don't want to loop through all the blobs in the container to do this.

If you're using Storage REST API, that's the only way to do it. You will need to list blobs in the container and then loop through the blobs and do the filtering based on extension (or any other criteria) on the client side.

Possible Solution

One possible solution would be to use Azure Search Service and have your blob metadata indexed there. Then you should be able to search for a particular extension and get the list of blobs.

Sign up to request clarification or add additional context in comments.

Comments

2

You can use ListBlobsOptions() with setPrefix to filter based on prefix as shown below

ListBlobsOptions options=new ListBlobsOptions();
options.setPrefix("<<prefix>>");
Duration fromDays = Duration.of(10, ChronoUnit.MINUTES);
BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient("containerName");
for (BlobItem blobItem : containerClient.listBlobs(options,fromDays)) {
            System.out.println("\t" + blobItem.getName());
}

1 Comment

The last parameter to listBlobsl is timeout and not **lfromDays **l ``` public PagedIterable<BlobItem> listBlobs(ListBlobsOptions options, Duration timeout) { return this.listBlobs(options, null, timeout); } ```
-1

This is all you need

BlobContainer.ListBlobs(prefix, useFlatBlobListing: true, blobListingDetails: BlobListingDetails.None)
.OfType<CloudBlockBlob>()
.Where(x=> x.Name.EndsWith(".json"));

The prefix is just a partial path where search. The result is an IEnumerable<CloudBlockBlob>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.