2012-04-03 11 views
13

Sto tentando di ottenere alcune informazioni sul BLOB di Azure (ultima ora UTC modificata). Questa informazione è memorizzata proprietà CloudBlob.Properties.LastModifiedUtc.Archiviazione di Azure CloudBlob.Properties non viene inizializzato quando si utilizza GetBlobReference()

Se utilizzo il metodo GetBlobReference() o GetBlockBlobReference(), le proprietà del BLOB non sono inizializzate (LastModifiedUtc è DateTime.MinDate). Se utilizzo ListBlobs(), le proprietà vengono inizializzate correttamente (LastModifiedUtc ha il valore corretto).

Sto facendo qualcosa di sbagliato quando si utilizza la funzione GetBlobReference? C'è un modo per ottenere l'istanza di CloudBlob solo per un blob specifico? So che posso perdere ListBlobs() e filtrare solo il blob a cui sono interessato, o usare ListBlobsWithPrefix() dalla classe CloudBlobClient, ma mi aspetterei di ottenere tutti i metadati quando chiedo il Blob Reference specifico.

codice che mostra come sto lavorando con blob Azure:

string storageAccountName = "test"; 
    string storageAccountKey = @"testkey"; 
    string blobUrl = "https://test.blob.core.windows.net"; 
    string containerName = "testcontainer"; 
    string blobName = "testbontainer"; 

    var credentials = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey); 
    var cloudBlobClient = new CloudBlobClient(blobUrl, credentials); 
    var containerReference = cloudBlobClient.GetContainerReference(string.Format("{0}/{1}", blobUrl, containerName)); 

    // OK - Result is of type CloudBlockBlob, cloudBlob_ListBlobs.Properties.LastModifiedUtc > DateTime.MinValue 
    var cloudBlob_ListBlobs = containerReference.ListBlobs().Where(i => i is CloudBlob && ((CloudBlob)i).Name == blobName).FirstOrDefault() as CloudBlob; 

    // WRONG - Result is of type CloudBlob, cloudBlob_GetBlobReference.Properties.LastModifiedUtc == DateTime.MinValue 
    var cloudBlob_GetBlobReference = containerReference.GetBlobReference(string.Format("{0}/{1}/{2}", blobUrl, containerName, blobName)); 

    // WRONG - Result is of type CloudBlockBlob, cloudBlob_GetBlockBlobReference.Properties.LastModifiedUtc == DateTime.MinValue 
    var cloudBlob_GetBlockBlobReference = containerReference.GetBlockBlobReference(string.Format("{0}/{1}/{2}", blobUrl, containerName, blobName)); 

risposta

34

Credo che bisogna fare una chiamata separato per andare a prendere l'attributi/metadati. Dopo aver ottenuto il blob referrence, emettere la seguente riga per recuperare gli attributi.

cloudBlob_GetBlobReference.FetchAttributes();

+6

Per elaborare, GetBlobReference() non effettua alcuna chiamata di rete. Ti restituisce praticamente un oggetto inizializzato con l'URL corretto. Per ottenere gli attributi, è necessario effettuare una chiamata di rete, e .FetchAttributes() è il modo per farlo minimamente (fa una richiesta HEAD). – smarx

+0

Oh, grazie, non ero a conoscenza del fatto che GetBlobReference() è solo un metodo di produzione lato client, mi aspettavo che facesse una chiamata contro Azure e sono rimasto sorpreso che non portasse tutti i dati. Ora ha senso per me. – Tiny

+0

risposta inestimabile mi ha salvato molto –