2

我想列出容器中的 blob。对于桌面应用,Azure 存储 SDK 提供以下方法:

CloudBlobContainer container = blobClient.GetContainerReference("myBlob"); 
container.ListBlobs();

但是,使用WinRT 库时,该方法不存在(可能是由于其阻塞性质)。我应该改用什么?

4

2 回答 2

6

您需要使用ListBlobsSegmentedAsyncblob 容器上的函数来获取 blob 列表。例如,请参见下面的代码:

    CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
    var client = account.CreateCloudBlobClient();
    var container = client.GetContainerReference("containername");
    BlobContinuationToken continuationToken = null;
    string prefix = null;
    bool useFlatBlobListing = true;
    BlobListingDetails blobListingDetails = BlobListingDetails.All;
    int maxBlobsPerRequest = 10;
    List<IListBlobItem> blobs = new List<IListBlobItem>();
    do
    {
        var listingResult = await container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, maxBlobsPerRequest, continuationToken, null, null);
        continuationToken = listingResult.ContinuationToken;
        blobs.AddRange(listingResult.Results);
    }
    while (continuationToken != null);
于 2013-04-17T06:36:38.943 回答
0

修改代码以支持 Azure 2.2

CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containername");
BlobContinuationToken continuationToken = null;
string prefix = null;
bool useFlatBlobListing = true;
BlobListingDetails blobListingDetails = BlobListingDetails.All;
int maxBlobsPerRequest = 10;
List<IListBlobItem> blobs = new List<IListBlobItem>();
do
{
    var listingResult = await container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, maxBlobsPerRequest, continuationToken, null, null);
    continuationToken = **listingResult.Result.ContinuationToken;**
    blobs.AddRange(**listingResult.Result.Results**);
}
while (continuationToken != null);
于 2014-06-19T03:06:23.627 回答