Search code examples
c#.netazureazure-blob-storageazure-storage

will looping GetBlobsAsync() but doing nothing in the loop body read the contents of the blob


follow up question for this as advised in the comments

I have successfully managed to get the number of files in a certain prefix in Azure blob storage using the code (answer also in linked question)

            int count = 0;

            // Iterate through the blobs with the specified prefix
            await foreach (BlobItem blobItem in containerClient.GetBlobsAsync(prefix: folderPrefix))
            {
                count++;
            }

            return count;

Here i loop through the containerClient.GetBlobsAsync(prefix: folderPrefix) and in the loop body i just increment the count. I do not read any contents or anything using a blobItem

My question is will this still load the blob content to memory. Lets say my files are very large and I don't want the file content loaded to my app memory, just want to know the file exists.

I dont know how to verify this. can someone who knows about this help me with this?


Solution

  • If you check the docs you will see that GetBlobsAsync returns a AsyncPageable<BlobItem>

    A BlobItem is class holding data about the blob, not the content of the blob. If you check the BlobItem docs there is no Content property or any similar property.

    If you need to retreive the content of a blob use the "Download" methods