【发布时间】:2021-12-12 01:48:09
【问题描述】:
我正在尝试使用以下方式从 Azure 存储 blob 下载图像 (.jpg):
public static async Task DownloadToTemp(string path, string fileName)
{
string storageAccount_connectionString = "CONNECTION STRING";
CloudStorageAccount mycloudStorageAccount = CloudStorageAccount.Parse(storageAccount_connectionString);
CloudBlobClient blobClient = mycloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(CONTAINER);
CloudBlockBlob cloudBlockBlob = container.GetBlockBlobReference(fileName);
// provide the file download location below
Stream file = File.OpenWrite(path);
await cloudBlockBlob.DownloadToStreamAsync(file);
file.Close();
return;
}
但是当我尝试将图像打开为位图Bitmap image = new Bitmap(path) 时,我收到了错误System.ArgumentException: 'Parameter is not valid.'。我正在使用电话BlobHandler.DownloadToTemp(path, file).GetAwaiter() 来确保文件已下载。
【问题讨论】:
标签: c# azure azure-blob-storage azure-storage