c# - Windows Azure Blob 中来自 "subfolders"的输出图像

标签 c# asp.net .net azure azure-blob-storage

我有一个名为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 条件

中的 storageException

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/

相关文章:

java - 我可以使用 java 创建 Windows Phone 应用程序吗

asp.net - PostbackUrl 与 NavigateUrl

c# - 引用对象的地址在立即窗口中有效,但在编译代码中无效

c# - .net 4.6 项目中缺少 XML 文档注释的枚举类

c# - 我的应用程序退出后继续在进程中运行

c# - 如何设置基于参数值动态返回结果的模拟?

c# - File.Exists 为不存在的文件返回 true

asp.net - Visual Studio 2008、2010 或 2012 (v11) 是为使用多核而编写的吗?

c# - 获取asp :Hyperlink data-attribute through onclick event

c# - 如何验证 UPC 或 EAN 代码?