locked
WindowsAzure.Storage version 4+ 404 errors. RRS feed

  • Question

  • Hello.

    Below is a simplified version of code I am using to get information about blobs. This works fine on any version of Microsoft.WindowsAzure.Storage up to version 3.2.1. When I update to version 4.x the ListBlobs call works but FetchAttributes always throws a 404 error.

    I'm sure it is something simple but I just can't see what has changed between the versions. Anyway here is the code (the connection string is standard).

    var account = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["azConn"].ConnectionString);
    CloudBlobClient blobClient = account.CreateCloudBlobClient();
    CloudBlobContainer photoContainer = blobClient.GetContainerReference("pictures1");
    
    var blobItems = photoContainer.ListBlobs(null,true);
    
    foreach (var blobItem in blobItems)
    {
        Console.WriteLine(blobItem.Uri.ToString());
        CloudBlockBlob blob = photoContainer.GetBlockBlobReference(blobItem.Uri.ToString());
    
        try
        {
            blob.FetchAttributes();
        }
        catch (StorageException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }


    • Edited by JayChase Friday, October 31, 2014 12:03 AM
    Friday, October 31, 2014 12:02 AM

Answers

All replies

  • Hi,

    I have tested on my local, the version of my azure storage is 4.0.1.0, I think you need to check your code below.

      CloudBlockBlob blob = photoContainer.GetBlockBlobReference(blobItem.Uri.ToString());

    As far as I know, if your azure storage doesn't have a blob named "blobItem.Uri.ToString()", it will give us 404 error message, I don't know how the other version deals with this, if you use the latest one, please consider change your code as below.

     CloudBlobClient blobClient = account.CreateCloudBlobClient();
                CloudBlobContainer photoContainer = blobClient.GetContainerReference("bcv");
    
                var blobItems = photoContainer.ListBlobs(null, true);
    
                foreach (var blobItem in blobItems)
                {
                    Console.WriteLine(blobItem.Uri.ToString());
                    CloudBlockBlob blob = (CloudBlockBlob)blobItem;
    
                    try
                    {
                        blob.FetchAttributes();
                    }
                    catch (StorageException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 31, 2014 3:24 AM
  • Hi. I've checked the blobItem uri's are correct and exist. Did the code work for you on version 4.0.1.0? I am using the WindowsAzure.Storage nuget package. This code works fine up until the version 4 releases.
    Friday, October 31, 2014 5:01 AM
  • This is one of the breaking change in version 4.0 of Storage Client library. In the previous versions, you could create a reference for BlockBlob using blob's URI but with version 4.0, you would need to pass blob's name and not the URI. If you put a breakpoint after "CloudBlockBlob blob = photoContainer.GetBlockBlobReference(blobItem.Uri.ToString());" and notice the blob's URI property, you would see something like:

    https://account.blob.core.windows.net/container/https://account.blob.core.windows.net/container/blob.extension

    Please see this thread on Stack Overflow for more details: http://stackoverflow.com/questions/24986336/azure-cloudblockblob-cannot-find-the-blob-when-downloadtostream-uri-seems-repe/24990127#24990127

    Also see this link for breaking changes in storage client library: https://github.com/Azure/azure-storage-net/blob/master/BreakingChanges.txt

    Hope this helps


    • Edited by Gaurav Mantri Friday, October 31, 2014 2:39 PM
    • Marked as answer by JayChase Friday, October 31, 2014 11:51 PM
    Friday, October 31, 2014 2:38 PM
  • Thank you, that fixed it. Also it looks like I don't need to get the blob reference any more as CloudBlockBlob's are returned when calling ListBlobs so I can just do this:

    var blobItems = photoContainer.ListBlobs(null,true);
    
    foreach (CloudBlockBlob blobItem in blobItems)
    {  
        blobItem.FetchAttributes();
    
     /*...*/
    }

    Friday, October 31, 2014 11:51 PM