简体   繁体   English

从 Azure 下载 blob 图像

[英]Download blob images from Azure

In Xamarin Forms I'm trying to download blob images from Azure and store locally.在 Xamarin Forms 中,我尝试从 Azure 下载 blob 图像并在本地存储。 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?下面的第二个代码片段显示了我认为应该是什么,但我不确定应该传递给 GetBlockBlobReference 的内容,或者更确切地说是在哪里找到它,所以基本上我想从列出图像继续完成下载,任何人都可以建议我需要做什么?

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.您需要将路径传递到 blob 容器内的 blob。 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".因此,例如,如果 blob 的完整路径是“https://youraccount.blob.core.windows.net/container_name/folder1/folder2/file-name.bin”,那么您需要传递“folder1/folder2/file-name.bin”。斌”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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