8
votes

I was just wondering if it is possible to reference azure blob storage data in a SQL Azure table column?

For example, say I have a table called Users in my SQL Azure database, one of the columns in that table is UserImage, and instead of creating UserImage as a varbinary(MAX) and storing the image data directly in the table, I would instead like to store the image data in blob storage, get a reference to the blob data and store that reference in the UserImage (varchar??) column in the database, and then somehow, when reading the rows from the Users table, access the associated image data from blob storage using the reference to that data.

I am asking this because blob storage is considerably cheaper to use than binary/blob data directly within SQL Azure.

3

3 Answers

5
votes

You should be able to store the URL to the image in SQL Azure and have the client program parse the URL and display the image from the URL.

I can't think of any way to have SQL Azure directly go to Blob storage, nor do I see a need for this as most client programs will be able to work with the URL as well as with the BLOB.

6
votes

You should just store the image Url in SQL Azure, here is a short snippet to upload a image to the Blob Storage and get its Url:

    // Fake stream that contains your image to upload
    Stream data; 

    // Get a handle on account, create a blob service client and get container proxy
    var container = Account.CreateCloudBlobClient()
                        .GetContainerReference("my-fake-container");

    // Create a blob in container and upload image bytes to it
    var blob = container.GetBlobReference("my-fake-id");
    blob.Properties.ContentType = "image/jpeg";
    blob.UploadFromStream(data);

    // Get your iage Url in the Blob storage
    var imageUrl = blob.Uri;

You now just have to store imageUrl in your row.

0
votes

Yes....You can do that by storing url in SQL Azure or some other place and then getting the url and passing it to the blob object

void DoSthWithBlob(Uri blobUri, StorageCredentials credentials){
    var blob = new CloudBlob(blobUri, credentials);
    blob.FetchAttributes();           
}