我想在容器中列出blob。对于桌面应用程序,Azure Storage SDK提供以下方法:
CloudBlobContainer container = blobClient.GetContainerReference("myBlob");
container.ListBlobs();
但是,使用WinRT library方法不存在(可能是由于其阻塞性质)。我该怎么用?
答案 0 :(得分:6)
您需要在blob容器上使用ListBlobsSegmentedAsync
函数来获取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);
答案 1 :(得分: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);