Question background:
I have a basic MVC 4 site and am trying to display a picture that is stored in a blob storage container in my Azure cloud account. I store a list of image Uri's
in a string List
and pass these to a View
where they should display
The Issue:
I can't seem to get the file name of the image stored in the container.
The following image shows the container in Azure. Note that there is an image stored in it with a size of 101.28KB:
This is the code I am trying to use to retrieve the blobs and then read the image Uri's
:
AzureStorageController
with a Pics
Action Method:
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);
}
The GetCloudBlobContainer
Method of the myBlobStorageService
class:
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;
}
The Pics
View:
@{
ViewBag.Title = "Pics";
}
<h2>Pics</h2>
@foreach (var item in Model)
{
<img src="@item" alt="picture" width="200" height="200" />
}
The Uri that is in the list that is being passed to the Pics View is: https://fmfcpics.blob.core.windows.net/images/myblob but it does not feature the image file name.
Any help with this would be appreciated.
As Guarav has stated already, a good thing to check would be to make sure your container is not "Private".