I\'m developing an ASP.Net MVC 4 app and I\'m using Azure Blob to store the images that my users are going to upload. I have the following code:
var storag
it's necessary view the httpstatusmessage in exception: in my case the error was because The requested URI does not represent any resource on the server.
so i've seen that my BlobContainerName
not contains the right container (or not exists)
CloudBlobContainer container = > blobClient.GetContainerReference(BlobContainerName);
other case i've seen is the wrong name of container. blobcontainername that must be a name like "mycontainer1" or "mycontainer2" and so on
here the code to add container
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(BlobContainerName);
container.CreateIfNotExists();
//creo se non esiste e aggiungo i permessi
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(containerPermissions);
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(Filename);
blockBlob.UploadFromStream(inFileUpload);
}
catch (Exception ex)
{
return "";
}