listblobs in $logs container

We have a azure blob storage, with logging enabled. I can view these logs and download the blobs using the Management Portal. But now I'm trying to list those logs using the Client api. Something along the lines:

let account = new CloudStorageAccount(credentials, true)
let client = account.CreateCloudBlobClient()
let container = client.GetContainerReference "$logs"
container.ListBlobs()

But this throws a web exception code 400 Bad Request . I can. however, list blobs from other containers on this client. I understand I need to be authenticated for this container, but I'm using the primary access key for the credentials. So why can't I get the $logs blobs?

Thanks


As I mentioned in my comments above, you would need to use the latest version of storage client library which you can get from Nuget: http://nuget.org/packages/WindowsAzure.Storage/.

Here's the sample code:

open Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage.Auth
open Microsoft.WindowsAzure.Storage.Blob

[<EntryPoint>]
let main argv = 
    let credentials = new StorageCredentials("accountname", "accountkey")
    System.Console.WriteLine(credentials.AccountName)
    let account = new CloudStorageAccount(credentials, true)
    System.Console.WriteLine(account.BlobEndpoint)
    let client = account.CreateCloudBlobClient();
    let container = client.GetContainerReference "$logs"
    System.Console.WriteLine(container.Uri)
    let blobs = container.ListBlobs("", true, BlobListingDetails.All, null, null);
    for blob in blobs do
        System.Console.WriteLine(blob.Uri)
    let response = System.Console.ReadLine()
    0 // return an integer exit code

Above code needs Storage Client Library 2.0.

The reason you're getting back only one item is because you're calling ListBlobs function with no parameters. If you look at the definition for this function here (http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx), you'll see that you can get all blobs in a blob container by specifying useFlatBlobListing parameter to true (which I did in the code above). Do give it a try, it would return a list of all blobs in your blob container.

链接地址: http://www.djcxy.com/p/66104.html

上一篇: blob的创建给403 Forbidden消息

下一篇: $ logs容器中的listblobs