我想将 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)
Run Code Online (Sandbox Code Playgroud)
由于我没有使用过 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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4141 次 |
| 最近记录: |