简体   繁体   中英

Download blob images from Azure

In Xamarin Forms I'm trying to download blob images from Azure and store locally. Th code below works, but at the moment all I can do is loop through the names of each image, I'm struggling with the download part.

The second code snippet below shows what I think it should be but I'm unsure what should be passed in to GetBlockBlobReference, or rather where to find this, so basically I want to move on from listing the images to completing the download, can anyone suggest what I need to do?

public async Task ProcessAsync()
{
    storageAccount = CloudStorageAccount.Parse(Resx.Apis.BlobStorageDev);

    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference(Resx.AppResources.blobContainer);

    BlobContinuationToken blobContinuationToken = null;
    do
    {
        var results = await container.ListBlobsSegmentedAsync(null, blobContinuationToken);
        blobContinuationToken = results.ContinuationToken;
        await DownloadAsync(results);
        foreach (IListBlobItem item in results.Results)
        {
            // here we'll check against what's in local, download if needed
            Debug.WriteLine(item.Uri);

        }
    } while (blobContinuationToken != null); 
}

the download bit:

CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(???);
foreach (var listBlockItem in await cloudBlockBlob.DownloadBlockListAsync(BlockListingFilter.All, null, null, null))
{

}

You need to pass the path to the blob inside blob container. So if for example full path to blob is "https://youraccount.blob.core.windows.net/container_name/folder1/folder2/file-name.bin" then you need to pass "folder1/folder2/file-name.bin".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM