Can I get blob using its url?

I store the Azure blob url in my database. Can I get blob using this url? Actually I need to update blob, and at the same time I need validations. Therefore, I need to convert this database entity model to my local model and apply validations for them. But in my local model, I have an Id file, Name, HttpPostedFileBase. When I insert blob, I get url blob and save it in the database. But how to get this blob when updating? This is my local model.

public class BlobAppModel { public int Id { get; set; } [Required(ErrorMessage="Please enter the name of the image")] [Remote("IsNameAvailable","Home",HttpMethod="POST",ErrorMessage="Name Already Exists")] public string Name { set; get; } [Required(ErrorMessage="Please select an image file")] public HttpPostedFileBase File { set; get; } } 

My essential model is

 public partial class BlobApp { public int Id { get; set; } public string Name { get; set; } public string Uri { get; set; } } 

When I edit it, I need to get a blob .. I am stuck here. Can anyone help me out?

 public ActionResult Edit(string Id) { var data=BlobManager.GetBlob(Convert.ToInt32(Id)); BlobStorageServices _blobstorageservice = new BlobStorageServices(); CloudBlobContainer container = _blobstorageservice.GetCloudBlobContainer(); CloudBlockBlob blob = container.GetBlockBlobReference(data.Uri.ToString()); BlobAppModel model = new BlobAppModel { Id = data.Id, Name = data.Name, File =//This is where I need to get the file//}; return View("Edit",BlobManager.GetBlob(Convert.ToInt32(Id))); } 
+7
asp.net-mvc blob azure-storage-blobs model-validation
source share
4 answers

The best way to access the blob is to access the repository with the container name and a link to blob, as described here: https://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage / # download-blobs In your code, you need to change the blob link to the name you set at boot, not uri.

 CloudBlockBlob blob = container.GetBlockBlobReference(data.Uri.ToString()); 

use this instead:

 CloudBlockBlob blob = container.GetBlockBlobReference("yourfile.jpg"); 

If you have a blob url and the container is shared, you can get the data simply by downloading it using a regular http client.

+6
source share
  CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); CloudBlockBlob blob = new CloudBlockBlob(new Uri(imgUrl),storageAccount.Credentials); 
+12
source share

As Christian mentioned, you can use GetBlockBlobReference if you have your blob name. Otherwise, if you want to use the full URL, you can simply create a new CloudBlockBlob object using one of its constructors

+7
source share

You can get a link to blob using blob Uri and container. For example, if you need to update or remove blob, and you already have a container with credential settings:

 var blob = container.ServiceClient.GetBlobReferenceFromServer(blobUri); 
+1
source share

All Articles