Search code examples
azureblobstorage

Azure Storage returning no blobs when 1827 shown in azure explorer


I am trying to set the proper content type after uploading almost 2000 images , not realizing I had to set their ContentType property. Fortunately I realized that before I moved from the .png files to some other type.

Here is my method:

private static void ChangeImageTypeInAzureStorage()
    {
        var client = GetAzureClient();
        var blobContainer = client.GetContainerReference("accessibleimages");
        var list = blobContainer.ListBlobs().OfType<CloudBlockBlob>().ToList();

        if (!list.Any()) return; //log no entries returned
        try
        {
            foreach (var item in list)
            {

                if (Path.GetExtension(item.Uri.AbsoluteUri) == ".png")
                {
                    item.Properties.ContentType = "image/png";
                }
                item.SetProperties();
            }
        }
        catch (Exception ex)
        {
            //log exceptions with your own methods
            Console.WriteLine(ex);
        }
        Console.WriteLine("Done... press a key to end.");
        Console.ReadKey();
    }

I'm not getting why nothing is returned to list. The client and blobContainer are correct. I had no problem uploading those images to the same client blobContainer. Needless to say it fails because the list always has a count of 0.

Any help appreciated.


Solution

  • Well, I found the answer after a lot of googling. The boolean parameter useFlatBoolListing for the ListBlobs method has to be set to true.

     var list = blobContainer.ListBlobs(null, true).OfType<CloudBlockBlob>().ToList();