如何从在线azure blob存储下载文件

时间:2017-11-27 07:23:46

标签: c# azure-storage-blobs azure-blob-storage

当我尝试从在线azure blob下载图像文件时,它会抛出异常,因为"不支持给定路径的格式"。我的代码块如下:

StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
container = client.GetContainerReference(blobName);


CloudBlockBlob blockBlob = container.GetBlockBlobReference(MyPath);
await blockBlob.DownloadToFileAsync(Path, FileMode.OpenOrCreate);


using (var fileStream = System.IO.File.Create(Path))
{
    await blockBlob.DownloadToStreamAsync(fileStream);
}

如果我提供本地路径为" c:\ users \ Joy \ Downloads"在路径中,如下所示:

var localPath = @"C:\Users\Joy \Downloads\user.jpg" ;
await blockBlob.DownloadToFileAsync(localPath, FileMode.OpenOrCreate);

using (var fileStream = System.IO.File.Create(localPath))
{
    await blockBlob.DownloadToStreamAsync(fileStream);
}

可以将其复制到相应的位置。但我无法在自定义位置下载该文件。

0 个答案:

没有答案