Microsoft Certified: Azure Developer Associate (AZ-204)Develop for Azure storageMedium
A developer is building a .NET application that needs to list all blobs within a specific virtual directory (folder) in an Azure Blob Storage container. The virtual directory structure is 'category/subcategory/item.jpg'. The developer wants to retrieve only the blobs under 'images/thumbnails/'.
- AUse the `GetBlobs` method and filter the results client-side after retrieval.
- BUse the `GetBlobs` method with the `delimiter` parameter set to '/'.
- CUse the `GetBlobs` method with the `prefix` parameter set to 'images/thumbnails/'.
- DUse the `GetBlobs` method without any parameters.
Show answer & explanationAnswer & explanation
Correct answer: C. Use the `GetBlobs` method with the `prefix` parameter set to 'images/thumbnails/'.
To efficiently list blobs within a specific virtual directory, the `GetBlobs` method (or its equivalent in other SDKs) should be used with the `prefix` parameter. Setting the `prefix` to 'images/thumbnails/' will instruct Azure Blob Storage to return only blobs whose names start with that string, effectively listing contents of the virtual directory.
Why the other options are wrong
- A. Filtering client-side is inefficient as it requires downloading metadata for all blobs before filtering, wasting bandwidth and processing.
- B. The `delimiter` parameter is used with `prefix` to simulate hierarchical listing and return only top-level virtual directories and blobs within the specified prefix, not just all blobs under a specific prefix.
- D. Using `GetBlobs` without parameters would list all blobs in the container, which is inefficient.
Azure Blob Listing with Prefix
When listing blobs in Azure Blob Storage, the `prefix` parameter allows you to filter the results to only include blobs whose names begin with the specified string, effectively simulating listing contents of a virtual directory.
- Filters blobs server-side, improving efficiency.
- Useful for querying 'virtual directories' in flat blob storage.
- Can be combined with `delimiter` for hierarchical listing.
Memory trick: Prefix points to the folder's path.