gpt4 book ai didi

c# - 来自 Azure Blob 下载图像的链接,但我只需要观看(Asp.NET Core)

转载 作者:行者123 更新时间:2023-12-03 05:42:34 29 4
gpt4 key购买 nike

我有代码将图像上传到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();
}

结果我得到了网址

当我打开它时,图像正在下载。我只需要看一下,我的问题出在哪里?

最佳答案

如果此答案未反射(reflect)所需/预期的行为,请忽略此答案。

--- 观察到 ---

如果网络浏览器按如下方式下载图像 blob:

enter image description here

---预期---

并且,所需的行为是网络浏览器将其呈现如下:

enter image description here

--- 修复 ---

然后,将以下行添加到您的代码中:

blockBlob.Properties.ContentType = "image/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();
}

---引用文献---

https://www.iana.org/assignments/media-types/media-types.xhtml#image 中查找图像的 MIME 类型列表.

关于c# - 来自 Azure Blob 下载图像的链接,但我只需要观看(Asp.NET Core),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57546787/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com