将图像从Azure Blob存储转换为Base64? [英] Converting image from azure blob storage to Base64?

查看:160
本文介绍了将图像从Azure Blob存储转换为Base64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将映像从Azure blob存储转换为base64:

I'm trying to convert image from Azure blob storage to base64:

private static string FromAzureToBase64(string azureUri)
{
    Uri blobUri = new Uri(azureUri);
    CloudBlockBlob blob = new CloudBlockBlob(blobUri, StorageAccount.Credentials);

    byte[] arr = new byte[blob.Properties.Length];
    blob.DownloadToByteArray(arr, 0);
    var azureBase64 = Convert.ToBase64String(arr);
    return azureBase64;
}

arr参数的问题是我应该定义其长度,但是blob.Properties.Length的值是-1,但是该图像存在于Azure上,但是几乎所有其属性都为null或未指定:

The problem with arr parameter is that I should define its length, but the value of blob.Properties.Length is -1, however the image exists on Azure, but almost all its properties either null or unspecified:

推荐答案

您可以做的是获取blob的属性,然后填充blob的length属性.因此您的代码将是:

What you could do is fetch the blob's properties and then blob's length property will be populated. So your code would be:

private static string FromAzureToBase64(string azureUri)
{
    Uri blobUri = new Uri(azureUri);
    CloudBlockBlob blob = new CloudBlockBlob(blobUri, StorageAccount.Credentials);
    blob.FetchAttributes();//Fetch blob's properties
    byte[] arr = new byte[blob.Properties.Length];
    blob.DownloadToByteArray(arr, 0);
    var azureBase64 = Convert.ToBase64String(arr);
    return azureBase64;
}

这篇关于将图像从Azure Blob存储转换为Base64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆