我如何从天蓝色存储容器中变成所有斑点,而不仅仅是根中的斑点?
private CloudBlobContainer GetCloudBlobContainer()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=*;AccountKey=*;EndpointSuffix=core.windows.net");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("test123");
return container;
}
public ActionResult ListBlobs()
{
CloudBlobContainer container = GetCloudBlobContainer();
List<string> blobs = new List<string>();
BlobResultSegment resultSegment = container.ListBlobsSegmentedAsync(null).Result;
foreach (IListBlobItem item in resultSegment.Results)
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blobs.Add(blob.Name);
}
else if (item.GetType() == typeof(CloudPageBlob))
{
CloudPageBlob blob = (CloudPageBlob)item;
blobs.Add(blob.Name);
}
//Directory
else if (item.GetType() == typeof(CloudBlobDirectory))
{
CloudBlobDirectory dir = (CloudBlobDirectory)item;
blobs.Add(dir.Uri.ToString());
}
}
return View(blobs);
}
该代码仅返回根目录上的blob。但我也想在目录中添加blob。
谢谢
答案 0 :(得分:0)
在调用useFlatBlobListing
方法时,请指定ListBlobsSegmentedAsync
为true。