【发布时间】:2016-02-02 22:12:59
【问题描述】:
我正在尝试使用代码从单个 Azure 容器下载所有 Blob。当我下载每个 Blob 时,我希望新文件名是从 2.jpg 向上到 3.jpg、4.jpg 5.jpg 等的连续数字。这不是 azure 容器中 Blob 的名称,我不知道代码运行时每个 Blob 的名称。
我似乎遇到了最后一个障碍,我不知道应该在我的foreach 块中放入什么文件才能将文件放入本地硬盘驱动器上的\home\pi\Pictures\ 目录中。
urls.DownloadToStream(FileStream); 抛出一个错误,
List String 不包含 DownloadToStream 的定义
和
FileStream 是在给定上下文中无效的类型。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
namespace CPGetAdverts
{
class Program
{
static void Main(string[] args)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureImagesConnection"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("xxxxxx/").ListBlobs();
// Retrieve filenames from container List
var urls = new List<string>();
int fileName = 2;
foreach (var blob in container)
{
using (var fileStream = System.IO.File.OpenWrite(@"\home\pi\Pictures\"+ fileName + ".jpg")) ;
urls.DownloadToStream(FileStream);
fileName++;
}
}
}
}
非常感谢任何帮助。
【问题讨论】:
标签: c# azure azure-blob-storage