gpt4 book ai didi

asp.net-mvc-4 - Azure blob - 无法在 MVC 4 中的 blob 容器中显示图像存储

转载 作者:行者123 更新时间:2023-12-03 04:33:57 25 4
gpt4 key购买 nike

问题背景:

我有一个基本的 MVC 4 站点,并尝试显示存储在我的 Azure 云帐户的 Blob 存储容器中的图片。我将图像 Uri's 的列表存储在字符串 List 中,并将它们传递给应显示的 View

问题:

我似乎无法获取存储在容器中的图像的文件名。

下图显示了 Azure 中的容器。 注意里面存储了一张大小为101.28KB的图片:

enter image description here

这是我尝试用来检索 Blob 然后读取图像 Uri 的代码:

AzureStorageControllerPics 操作方法:

 public ActionResult Pics()
{
var imageList = new List<string>();

var imagesAzure = new myBlobStorageService();

var container = imagesAzure.GetCloudBlobContainer();

foreach (var blobItem in container.ListBlobs())
{
imageList.Add(blobItem.Uri.ToString());
}
return View(imageList);
}

myBlobStorageService 类的 GetCloudBlobContainer 方法:

 public CloudBlobContainer GetCloudBlobContainer()
{
string accountName = "fmfcpics";

string accountKey = "xxxxxx/yyyyyyyyy/3333333333==";

StorageCredentials credentials = new StorageCredentials(accountName, accountKey);

CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("images");

if (container.CreateIfNotExists())
{
container.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
}

return container;
}

图片 View :

@{
ViewBag.Title = "Pics";
}

<h2>Pics</h2>

@foreach (var item in Model)
{
<img src="@item" alt="picture" width="200" height="200" />
}

传递到图片 View 的列表中的 Uri 为: https://fmfcpics.blob.core.windows.net/images/myblob 但它不包含图像文件名。

如有任何帮助,我们将不胜感激。

最佳答案

正如 Guarav 已经指出的那样,检查的一件好事是确保您的容器不是“私有(private)”的。

关于asp.net-mvc-4 - Azure blob - 无法在 MVC 4 中的 blob 容器中显示图像存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30925194/

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