4
votes

These are great guides for migrating between the different versions of NuGet package: https://github.com/Azure/azure-sdk-for-net/blob/Azure.Storage.Blobs_12.6.0/sdk/storage/Azure.Storage.Blobs/README.md https://elcamino.cloud/articles/2020-03-30-azure-storage-blobs-net-sdk-v12-upgrade-guide-and-tips.html

However I am struggling to migrate the following concepts in my code:

// Return if a directory exists:
container.GetDirectoryReference(path).ListBlobs().Any();

where GetDirectoryReference is not understood and there appears to be no direct translation

Also, the concept of a CloudBlobDirectory does not appear to have made it into Azure.Storage.Blobs e.g.

        private static long GetDirectorySize(CloudBlobDirectory directoryBlob) {
            long size = 0;

            foreach (var blobItem in directoryBlob.ListBlobs()) {
                if (blobItem is BlobClient)
                    size += ((BlobClient) blobItem).GetProperties().Value.ContentLength;

                if (blobItem is CloudBlobDirectory)
                    size += GetDirectorySize((CloudBlobDirectory) blobItem);
            }

            return size;
        }

where CloudBlobDirectory does not appear anywhere in the api

1

1 Answers

3
votes

There's no such thing as physical directories or folders in Azure Blob Storage. The directories you sometimes see are part of the blob (e.g. folder1/folder2/file1.txt). The List Blobs requests allows you to add a prefix and delimiter in a call, which are used by the Azure Portal and Azure Data Explorer to create a visualization of folders. As example prefix folder1/ and delimiter / would allow you to see the content as if folder1 was opened.

That's exactly what happens in your code. The GetDirectoryReference() adds a prefix. The ListBlobs() fires a request and Any() checks if any items return.

For V12 the command that'll allow you to do the same would be GetBlobsByHierarchy and its async version. In your particular case where you only want to know if any blobs exist in the directory a GetBlobs with prefix would also suffice.