【发布时间】:2019-03-19 15:40:33
【问题描述】:
我收到的图像数据是 base 64 编码字符串,我需要显示图像的内容而不将其下载到服务器。
在浏览器中访问 URL 时,我的图像无法正常显示
代码
public async static Task<dynamic> UploadImageToStorage(string imageData)
{
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(BlobStorageConnectionString);
try
{
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(BlobStorageContainer);
if (await container.CreateIfNotExistsAsync())
{
await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
string blobID= Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobID);
blockBlob.Properties.ContentType = "image/jpeg";
await blockBlob.UploadTextAsync(imageData);
return blockBlob.Uri.AbsoluteUri;
//return blobID;
}
它是这样显示的
【问题讨论】:
-
为什么要将图像数据作为文本上传?
-
编辑了我的问题
-
请编辑您的问题并包括 imageData 的样子。
-
@GauravMantri 它是问题中所述的base64值
-
我之所以要求查看实际值是因为您需要将该 base64 编码字符串转换为字节数组。该值将决定在转换之前是否需要解析。
标签: azure azure-storage