我正在尝试使用:
从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()
来确保文件已下载。
所以问题在于没有完全等待图像被存储:添加:
await BlobHandler.DownloadToTemp(path, file);
确保文件被完全下载(这意味着callerfunction必须是异步的)。