【问题标题】:Downloading Image from Azure Blob C#从 Azure Blob C# 下载图像
【发布时间】: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


    【解决方案1】:

    所以问题在于没有完全等待图像被存储: 添加:

    await BlobHandler.DownloadToTemp(path, file);
    

    确保文件完全下载(这意味着调用函数必须是异步的)。

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 1970-01-01
      • 2018-11-21
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 2013-01-21
      相关资源
      最近更新 更多