Uploading Stream in AZURE BLOB

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

Set the Connection String as below,


Function is as below,

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

    s.Seek(0, SeekOrigin.Begin);
    // set the required content type 
    blob.Properties.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    BlobRequestOptions options = new BlobRequestOptions();
    options.AccessCondition = AccessCondition.None;
    blob.UploadFromStream(s, options);

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

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.  

Up Next
    Ebook Download
    View all
    View all