JReam
JReam

Reputation: 898

Did Azure Blob Storage Library Change?

I've been using WindowsAzure.Storage 8.* library to work with a container to move some blobs around. Recently, I wanted to get a list of blobs using the the below code from the example on the Microsoft site. (https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-how-to-use-blobs#set-up-your-development-environment) When I attempted to use the 'ListBlobs()', the method is no longer available via the library. I was using this in console apps whereas now I'm attempting to use this in a .net core web application. Is there a different approach to get a list of blobs in different environments? I'm just not sure why the method is not available in the same namespace/library/version...?

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("photos");

// Loop over items within the container and output the length and URI.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
    CloudBlockBlob blob = (CloudBlockBlob)item;

    Console.WriteLine("Block blob of length {0}: {1}",    blob.Properties.Length, blob.Uri);

}
else if (item.GetType() == typeof(CloudPageBlob))
{
    CloudPageBlob pageBlob = (CloudPageBlob)item;

    Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);

}
else if (item.GetType() == typeof(CloudBlobDirectory))
{
    CloudBlobDirectory directory = (CloudBlobDirectory)item;

    Console.WriteLine("Directory: {0}", directory.Uri);
}
}

Upvotes: 2

Views: 969

Answers (3)

fballer87
fballer87

Reputation: 74

As Brando said they brought the synchronous methods back in that SDK but its now deprecated.

...use Azure Storage Blobs

Upvotes: 0

Jeevan
Jeevan

Reputation: 538

From 9.4.2 SDK, Microsoft has brought back the sync implementations: https://github.com/Azure/azure-storage-net/tree/master/Blob

Upvotes: 1

Brando Zhang
Brando Zhang

Reputation: 28077

According to this question: Missing syncronous methods for dotnet core?,NetCore/Netstandard support does not yet include Sync implementation of the APIs.

Since ListBlobs is a synchronous method and therefore is missing on platforms that do not support synchronous methods, so you cloud only call ListBlobsSegmentedAsync and handle the continuation token it returns.

More details about how to use ListBlobsSegmentedAsync to list the blob, you could refer to follow link’s example: CloudBlobClient.ListBlobsSegmentedAsync Method

Upvotes: 3

Related Questions