我有一个通用 Windows 应用程序。
我试图在应用程序启动时从 azure 容器下载所有 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 does not contain a definition of Uri.
Cannot declare variable of static type File.
和
Cannot create an instance of the static class file.
最佳答案
您需要使用 container.listBlobsSegmentedAsync()
枚举容器中的 Blob。容器引用不仅仅包含自动下载的 blob 列表。
有关引用,请参阅here .
关于c# - Windows 通用应用程序 - 从 Azure 容器下载所有 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35232272/