简体   繁体   中英

Output images from “subfolders” in Windows Azure Blobs

I have a container called systemdesign which have several subfolders for example dfd usecase and other UML design tool names. I want to show the images of a particular "folder" for example dfd, rather than all the images found inside this container.

Below are some screenshots, and partial code that revolves around this. Please do not mind the nature of the images those are just test data.

http://i.imgur.com/fVs1SZk.png [Shows everything rather than a container] EDIT: For example in folder dfd there should be just one picture, 2nd folder should be another 3.

http://i.imgur.com/kMyBLca.png [How my "directories" are sectioned]

The Code that affects the above:

SystemDesignController

// 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 // This class holds the model and ultimately is used in the View to show the images

  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 Partial Code For the View that affects this

@foreach (var item in Model.Files)
{
        <a href="@item.URL"><img src="@item.URL" height="128" width="128"/></a>
}

What I have tried to do by now:

1) I tried changing CloudBlobContainer storageContainer = blobClient.GetContainerReference("systemdesign"); from systemdesign to dfd but it issued me a 404 and a storageException in SystemDesignModel.cs if condition

2) tried useFlatBlobListing as false but it output nothing.

Any idea how I can output just one folder according to the section I want?

Thanks

When listing blobs in a container, you can pass a blob prefix which is essentially the name of the folder (dfd, usecase etc. in your example). Then you will only see the blobs in that folder. Here's the link to the documentation: https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM