I can't seem to get metadata or static date from blobs

回答済み I can't seem to get metadata or static date from blobs

  • Sunday, December 12, 2010 4:51 PM
     
      Has Code

    When I call ListBlobs with the option BlobListingDetails.All I can see in the response (fiddler) that all the data is accounted for, but through the storage api, the data does not seem to get populated.  I can't find any examples on line but I'm thinking I'm missing something.  I don't want to call fetchattributes because that causes a request on every item and the data I want is already in the response.  Below is some trivial code I wrote that demonstrates this.  Specifically, I'm looking for the LastModified date.

    namespace ConsoleApplication
    {
      class Program
      {
        static void Main(string[] args)
        {
          string accountName = "peterstest";
          string accountKey =
            "xxxxxshNvjftZFD7sEc/hYA7Jub1Ah9QB2OowPvG8++IgmI8O5zg==";
          var storageAccount =
            new CloudStorageAccount(new StorageCredentialsAccountAndKey(accountName, accountKey), true);
    
          CloudBlobClient blogStorage =
            storageAccount.CreateCloudBlobClient();
          var CbContiner = blogStorage.GetContainerReference("1-4d794d75736963536d616c6c");
    
          var opts = new BlobRequestOptions
          {
            UseFlatBlobListing = true,
            BlobListingDetails = BlobListingDetails.All
          };
          var blobs = CbContiner.ListBlobs(opts);
    
          var recs = (from cloudBlob in blobs
                select cloudBlob).ToList();
    
          foreach (var rec in recs)
          {
            Console.WriteLine("rec: " + rec.Container.Properties.LastModifiedUtc);
          }
        }
      }
    }
    
    


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider

All Replies

  • Sunday, December 12, 2010 7:53 PM
    Answerer
     
     Answered Has Code

    You are looking at the last modified date of a container not of the blobs in it. If you look at Fiddler you can see this information is not returned. The LastModifiedUtc of the individual blobs is and is exposed through the Storage Client Library as follows:

    public static void ListBlobs(CloudBlobClient cloudBlobClient, String containerName)
    {
    	CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
    
    	BlobRequestOptions blobRequestOptions = new BlobRequestOptions()
    		{
    			BlobListingDetails = BlobListingDetails.All,
    			UseFlatBlobListing = true
    		};
    
    	IEnumerable<IListBlobItem> blobList = cloudBlobContainer.ListBlobs(blobRequestOptions);
    	foreach (IListBlobItem item in blobList)
    	{
    		CloudBlockBlob cloudBlockBlob = item as CloudBlockBlob;
    		if (cloudBlockBlob != null)
    		{
    			DateTime lastModifiedUtc = cloudBlockBlob.Properties.LastModifiedUtc;
    		}
    	}
    }
    
    
  • Sunday, December 12, 2010 11:48 PM
     
     Answered

    Thanks Neil,

    I'm also wondering how to get all of the records, not just the first 5000.  I don't see the value in BlobRequestOptions.

    I heard your talk in San Francisco went well.  Sorry I missed it. I had another meetup in Palo Alto I'm the organizer for so I could not very well blow that one off

    BTW, in case anyone is looking, to get metadata use:

    string

     

     

    sha512PreString = cloudBLockBlob.Metadata[SHA512PreKey] ?? string.Empty;


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
  • Monday, December 13, 2010 1:31 AM
    Answerer
     
     

    Peter -

    You can use ListBlobsSegmented() which supports continuation tokens allowing you to sequence through the list of all blobs.

  • Monday, December 13, 2010 6:19 AM
     
     
    Is there anyway to not have it download 5000 in the first batch?  I'd prefer to download small batches, say 1000 every time, not 5000, then 1000,1000,1000,etc.
    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
  • Monday, December 13, 2010 7:09 AM
    Answerer
     
     

    The following is documented for the maxResults parameter for ListBlobsSegmented():

    A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the per-operation limit of 5000.