我有将图像上传到 azure blob 存储的代码这是上传图像的代码public async Task<string> UploadFile(IFormFile file) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_configuration.GetConnectionString("AccessKey")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("toosee"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName); using (var fileStream = file.OpenReadStream()) { await blockBlob.UploadFromStreamAsync(fileStream); } return blockBlob.Uri.ToString(); }结果我得到了网址当我打开它时,图像下载。我只需要看一下,我的问题出在哪里?
1 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
如果它没有反映所需/预期的行为,请忽略此答案。
- - 观察到的 - -
如果Web 浏览器正在下载图像 blob,如下所示:
- - 预期的 - -
并且,所需的行为是 Web 浏览器将其呈现如下:
- - 使固定 - -
然后,将以下行添加到您的代码中:
blockBlob.Properties.ContentType = "图片/png";
下面找到一个示例代码:
public static string UploadFile() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse("{Connection String}"); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("toosee"); CloudBlockBlob blockBlob = container.GetBlockBlobReference("customer_address.png"); blockBlob.Properties.ContentType = "image/png"; blockBlob.UploadFromFile(@"C:\\Temp\\customer_address.PNG"); return blockBlob.Uri.ToString(); }
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消