Microsoft Certified: Azure Developer Associate (AZ-204)Develop for Azure storageMedium

A developer is writing code to manage blobs in Azure Blob Storage. The application needs to retrieve a list of all JPEG images stored within a specific virtual folder (e.g., 'photos/2023/'). The solution should be efficient and avoid downloading unnecessary blob metadata. Which method should the developer use?

  1. AListBlobs with a prefix 'photos/2023/' and include=BlobProperties to get content type.
  2. BListBlobs with a prefix 'photos/2023/' and filter the results by checking the blob name ends with '.jpg'.
  3. CListBlobs with a prefix 'photos/2023/' and a delimiter '/' to enumerate virtual directories.
  4. DListBlobs with a prefix 'photos/2023/' and filter by file extension locally.
Show answer & explanation

Correct answer: B. ListBlobs with a prefix 'photos/2023/' and filter the results by checking the blob name ends with '.jpg'.

Using ListBlobs with a prefix 'photos/2023/' will efficiently retrieve only blobs within that virtual folder. Then, filtering the results by checking the blob name for '.jpg' will ensure only JPEG images are processed, without needing to download full blob properties or content.

Why the other options are wrong

  • A. Including BlobProperties (like content type) for every blob increases the data transferred and processing overhead if only the file extension is needed.
  • C. Using a delimiter '/' is for enumerating virtual directories, not for filtering specific file types within a virtual directory.
  • D. Filtering by file extension locally is correct, but the option implies downloading all properties, which might be unnecessary if not explicitly scoped.

Blob Listing with Prefix

The `ListBlobs` operation in Azure Blob Storage allows specifying a prefix to filter the returned blobs, effectively listing blobs within a virtual directory.

  • Server-side filtering for efficiency.
  • Treats hierarchical data like folders.
  • Can be combined with delimiters for directory enumeration.
  • Reduces data transfer and processing.

Memory trick: Listing blobs with a prefix is like searching a folder with a specific starting name.

More Develop for Azure storage questions