Converting image from azure blob storage to Base64?

前端 未结 1 1190
广开言路
广开言路 2021-01-23 17:46

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

private static string FromAzureToBase64(string azureUri)
{
    Uri blobUri = new Uri(azureUri);
         


        
1条回答
  •  执念已碎
    2021-01-23 17:54

    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;
    }
    

    0 讨论(0)
提交回复
热议问题