How do I create a connection between asp.net web app hosted on azure and Blob? The connection works perfectly when I upload files from my localhost to blob. But when i publish the web app on azure, the app is unable to store file in the blob. The only reason I can think why the file does not get uploaded is because of some sort of connection issue between the hosted asp.net web app and the blob
BlobStorageServices.cs
public class BlobStorageServices
{
public CloudBlobContainer GetCloudBlobContainer()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("ImageStorageAccountConn"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("myimages");
if (blobContainer.CreateIfNotExists())
{
blobContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
return blobContainer;
}
}
HomeController.cs
BlobStorageServices _blobStorageService = new BlobStorageServices();
[HttpPost]
public ActionResult Upload(HttpPostedFileBase image)
{
if (image.ContentLength > 0)
{
CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
CloudBlockBlob blob = blobContainer.GetBlockBlobReference(image.FileName);
blob.UploadFromStream(image.InputStream);
}
return RedirectToAction("Index");
}
Index.cshtml
<h2>Upload Image</h2>
<p>
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="image" />
<input type="submit" value="Upload" />
}
</p>
Not sure if the BlobStorageServices.cs file gets uploaded to azure when we publish the asp.net app via visual studio. ImageStorageAccountConn is the connecting string.
RoleEnvironment