在 Windows Azure Blob 中输出来自 "subfolders" 的图像
Output images from "subfolders" in Windows Azure Blobs
我有一个名为 systemdesign
的容器,它有几个子文件夹,例如 dfd
usecase
和其他 UML 设计工具名称。我想显示特定 "folder" 的图像,例如 dfd,而不是在此容器中找到的所有图像。
下面是一些截图,以及围绕此展开的部分代码。请不要介意图像的性质,这些只是测试数据。
http://i.imgur.com/fVs1SZk.png [显示所有内容而不是容器]
编辑:例如在文件夹 dfd
中应该只有一张图片,第二个文件夹应该是另外 3 张。
http://i.imgur.com/kMyBLca.png [我的 "directories" 是如何划分的]
影响上述的代码:
系统设计控制器
// 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 // 这个class持有模型,最终在视图中用于显示图像
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 影响此视图的部分代码
@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 和 storageException in SystemDesignModel.cs
if condition
2) 尝试将 useFlatBlobListing
作为 false
但它没有输出任何内容。
知道如何根据我想要的部分只输出一个文件夹吗?
谢谢
在容器中列出 blob 时,您可以传递一个 blob prefix
,它实际上是文件夹的名称(在您的示例中为 dfd、usecase 等)。然后您将只会看到该文件夹中的 blob。这是文档的 link:https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx.
我有一个名为 systemdesign
的容器,它有几个子文件夹,例如 dfd
usecase
和其他 UML 设计工具名称。我想显示特定 "folder" 的图像,例如 dfd,而不是在此容器中找到的所有图像。
下面是一些截图,以及围绕此展开的部分代码。请不要介意图像的性质,这些只是测试数据。
http://i.imgur.com/fVs1SZk.png [显示所有内容而不是容器]
编辑:例如在文件夹 dfd
中应该只有一张图片,第二个文件夹应该是另外 3 张。
http://i.imgur.com/kMyBLca.png [我的 "directories" 是如何划分的]
影响上述的代码:
系统设计控制器
// 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 // 这个class持有模型,最终在视图中用于显示图像
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 影响此视图的部分代码
@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 和 storageException in SystemDesignModel.cs
if condition
2) 尝试将 useFlatBlobListing
作为 false
但它没有输出任何内容。
知道如何根据我想要的部分只输出一个文件夹吗?
谢谢
在容器中列出 blob 时,您可以传递一个 blob prefix
,它实际上是文件夹的名称(在您的示例中为 dfd、usecase 等)。然后您将只会看到该文件夹中的 blob。这是文档的 link:https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx.