Azure Blob下载为字节数组错误“内存流不可扩展”

时间:2017-04-07 06:38:05

标签: azure

我想将blob作为字节数组下载,但上面提到错误。 我的代码如下

  Dim fullFileBytes() As Byte = {}
 Dim objAzureStorage As New AzureCloudStorage

                            Dim fullImageBlob As Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob = objAzureStorage.CloudContainer.GetBlockBlobReference(row(0))

                            fullImageBlob.DownloadToByteArray(fullFileBytes, 0)

1 个答案:

答案 0 :(得分:0)

由于我没有使用VB.Net,让我在C#中提供答案。基本上我所做的是读取内存流中blob的内容,然后将其转换为字节数组并返回该数组。

    private static byte[] ReadBlobInByteArray()
    {
        var cred = new StorageCredentials(accountName, accountKey);
        var account = new CloudStorageAccount(cred, true);
        var container = account.CreateCloudBlobClient().GetContainerReference("container-name");
        var blob = container.GetBlockBlobReference("blob-name");
        using (var ms = new MemoryStream())
        {
            blob.DownloadToStream(ms);
            return ms.ToArray();
        }
    }