I have a Universal Windows app.
I am trying to download all blobs from an azure container when the app starts. This is my code:
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);
}
Im getting errors on two lines:
var blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
File downloadedFile = new File(blobReference + ".jpg");
My errors are:
ListBlobItem does not contain a definition of Uri.
Cannot declare variable of static type File.
and
Cannot create an instance of the static class file.
You need to enumerate the blobs in the container, with
container.listBlobsSegmentedAsync()
. The container reference doesn't just have a list of blobs automatically downloaded with it.For reference, see here.