我有一个通用Windows应用程序。
我正在尝试在应用启动时从天蓝色容器中下载所有blob。这是我的代码:
public MainPage()
{
this.InitializeComponent();
downloadblobs();
}
public async void downloadblobs()
{
CloudStorageAccount storageaccount = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
CloudBlobClient blobClient = storageaccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("ContainerName");
//---------------------
int fileName = 1;
var client = storageaccount.CreateCloudBlobClient();
BlobContinuationToken continuationToken = null;
string prefix = null;
bool useFlatBlobListing = true;
BlobListingDetails blobListingDetails = BlobListingDetails.All;
int maxBlobsPerRequest = 2500;
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);
using (var fileStream = System.IO.File.OpenWrite(@"\NewImages\" + fileName + ".jpg"))
{
var blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
File downloadedFile = new File(blobReference + ".jpg");
fileName++;
}
}
while (continuationToken != null);
}
我在两行中遇到错误:
var blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
File downloadedFile = new File(blobReference + ".jpg");
我的错误是:
ListBlobItem不包含Uri的定义。
无法声明静态类型File的变量。
和
无法创建静态类文件的实例。
答案 0 :(得分:1)
您需要使用container.listBlobsSegmentedAsync()
枚举容器中的blob。容器引用不仅具有随其自动下载的blob列表。
供参考,请参阅here。