我现在关于azure-sdk-winRT中的方法 DownloadToStreamAsync ,但我无法实现此功能。如何从blob存储下载图像,并保存到本地文件夹?
答案 0 :(得分:2)
你可以尝试类似下面的内容(非常简单的骨骼实现,没有错误检查):
CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containername");
var blob = container.GetBlockBlobReference("imagename.ext");//e.g myimage.png
var file = await KnownFolders.PicturesLibrary.CreateFileAsync("imagename.ext", CreationCollisionOption.ReplaceExisting);
var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
await blob.DownloadToStreamAsync(stream);
await stream.FlushAsync();
stream.Dispose();
虽然有一些评论: