Azure Blob 下载为字节数组错误 "Memory Stream is not expandable"

标签 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)

最佳答案

由于我没有使用过 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();
        }
    }

关于Azure Blob 下载为字节数组错误 "Memory Stream is not expandable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43271267/

相关文章:

azure - 如何将 Application Insights 添加到现有 QnAMaker 应用程序

c# - Azure 函数 blob 绑定(bind)

azure - 将 Azure 订阅与 MSDN 订阅合并

azure - Hive:两点之间的距离

c# - 如何获取azure webjob/console应用程序的当前路径

azure - 尝试创建 Azure 镜像时出现无效 VHD 路径错误

rest - Office 365 OneDrive REST API - "invalid_client"

c# - 在 C# 中启动和停止 azure 分析服务

azure - 通过 ARM 模板为服务连接用户分配角色

c# - 如何检查 Azure Active Directory 中的用户是否属于特定组成员身份?