AZURE

Uploading Stream in AZURE BLOB

In this post I will show you to upload stream to Azure BLOB.

Set the Connection String as below,

image

 

Function is as below,

 


public void UploadBlob(Stream s, string fileName, string containerName, string connectionString )
        {
            account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(connectionString));
            blobClient = account.CreateCloudBlobClient();
            container = blobClient.GetContainerReference(containerName);
            blob = container.GetBlobReference(fileName);

            s.Seek(0, SeekOrigin.Begin);
            // set the required content type
            blob.Properties.ContentType = "image/jpeg";
            blob.SetProperties();
            BlobRequestOptions options = new BlobRequestOptions();
            options.AccessCondition = AccessCondition.None;
            blob.UploadFromStream(s, options);

        }


You need to set required content type. If you are uploading image then content type would be like below,

 

image

To use this function you need to pass ,

  1. Public container name
  2. BLOB name as filename
  3. Data connection string

I hope this quick code snippet was useful. Thanks for reading. Smile

About Dhananjay Kumar

Dhananjay Kumar is Developer, Blogger , Speaker, Learner , Mindcracker & Microsoft MVP.

Discussion

3 Responses to “Uploading Stream in AZURE BLOB”

  1. Just a code snippet and screenshot nothing else. You could describe it more. Looks funky.

    Posted by Stephan Knudsen | September 10, 2011, 9:28 pm

Trackbacks/Pingbacks

  1. Pingback: Windows Azure and Cloud Computing Posts for 9/1/2011+ - Windows Azure Blog - September 2, 2011

  2. Pingback: Monthly Report September 2011: Total Posts 28 « debug mode…… - October 1, 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,380 other followers

Tweets

Categories

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway. © Copyright 2012