我有一个名为systemdesign
的容器,其中有几个子文件夹,例如dfd
usecase
和其他UML设计工具名称。我想显示特定“文件夹”的图像,例如 dfd,而不是在此容器内找到的所有图像。
下面是一些屏幕截图以及围绕此的部分代码。请不要介意图像的性质,这些只是测试数据。
/image/xUqox.png [显示一切而不是容器]
编辑:例如,在文件夹 dfd
中应该只有一张图片,第二个文件夹应该是另外 3 张图片。
/image/ihM2v.png [我的“目录”是如何划分的]
影响上述内容的代码:
系统设计 Controller
// GET: SystemDesign
public ActionResult Index()
{
StorageCredentials credentials = new StorageCredentials(storagename, accountkey);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer storageContainer = blobClient.GetContainerReference("systemdesign");
Models.SystemDesignModel blobsList = new Models.SystemDesignModel(storageContainer.ListBlobs(useFlatBlobListing: true));
return View(blobsList);
}
SystemDesignModel.cs//该类保存模型并最终在 View 中用于显示图像
public class SystemDesignModel
{
public SystemDesignModel() : this(null)
{
Files = new List<SystemDesign>();
}
public SystemDesignModel(IEnumerable<IListBlobItem> list)
{
Files = new List<SystemDesign>();
if (list != null && list.Count<IListBlobItem>() > 0)
{
foreach (var item in list)
{
SystemDesign info = SystemDesign.CreateImageFromIListBlob(item);
if (info != null)
{
Files.Add(info);
}
}
}
else
{
}
}
public List<SystemDesign> Files { get; set; }
}
index.cshtml影响此的 View 的部分代码
@foreach (var item in Model.Files)
{
<a href="@item.URL"><img src="@item.URL" height="128" width="128"/></a>
}
我现在尝试做的事情:
1) 我尝试将 CloudBlobContainer storageContainer = blobClient.GetContainerReference("systemdesign");
从 systemdesign
更改为 dfd
,但它向我发出了404 和 SystemDesignModel.cs
if 条件
2) 尝试将 useFlatBlobListing
设置为 false
但没有输出任何内容。
知道如何根据我想要的部分仅输出一个文件夹吗?
谢谢
最佳答案
在容器中列出 blob 时,您可以传递 blob 前缀
,它本质上是文件夹的名称(示例中的 dfd、usecase 等)。然后您将只能看到该文件夹中的 blob。这是文档的链接:https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx .
关于c# - Windows Azure Blob 中来自 "subfolders"的输出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29436899/