Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a blob by using its url?

I am storing the Azure blob url into my database.Can I get the blob by using that url? Actually I need to update the blob and while doing that I need validations. So I need to convert that database entity model to my local model and apply the validations for them.But in my local model I am having Id,Name,HttpPostedFileBase file.When I am inserting the blob I am getting the blob url and saving it in database.But how to retrieve that blob while 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; }

    } 

An My entitymodel is this one

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

when I am Editing it I need to get the 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)));
        }
like image 267
Bharat Bhushan Avatar asked Nov 01 '13 08:11

Bharat Bhushan


People also ask

How do I access blob storage from URL?

By default, the URL for accessing the Blob service in a storage account is https://<your account name>. blob.core.windows.net. You can map your own domain or subdomain to the Blob service for your storage account so that users can reach it using the custom domain or subdomain.

Can I use blob URL?

No, Blob URLs/Object URLs can only be made internally in the browser. You can make Blobs and get File object via the File Reader API, although BLOB just means Binary Large OBject and is stored as byte-arrays. A client can request the data to be sent as either ArrayBuffer or as a Blob.

How do I create a blob URL?

createObjectURL() to create Blob url. The URL. createObjectURL() static method creates a DOMString containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created.


1 Answers

   CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

    CloudBlockBlob blob = new CloudBlockBlob(new Uri(imgUrl),storageAccount.Credentials);
like image 157
Sentinel Avatar answered Sep 30 '22 04:09

Sentinel