How to create an azure blob from grails application

Posted By : Chetan Hallan | 30-Sep-2015

In this blog we will learn about the Azure Blobs. Azure Blob is a service of storing large amounts of unstructured data, such as text or binary data, that can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob storage to expose data publicly to the world, or to store application data privately.

Use of Blob storage are as follows :-

  1. Serving images or documents directly to a browser.
  2. Storing files for distributed access.
  3. Streaming video and audio.
  4. Performing secure backup and disaster recovery.
  5. Storing data for analysis by an on-premises or Azure-hosted service

How to create a blob in azure storage?

Pre-requisites :-

  1. Create an azure storage account.
  2. After creation of account. You will get Account name and Account Key.
  3. Download Jar azure-storage-2.0.0.jar and build it in your build path. Jar is not version specific you can use any Jar of any version.

Code to create a blob in azure storage is as follows :-

public void create(){
		    // Retrieve storage account from connection-string.
		    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
		    // Create the blob client.
		   CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
		   // Get a reference to a container.
		   // The container name must be lower case	   
		   CloudBlobContainer container = blobClient.getContainerReference("catalog");
		   // Create the container if it does not exist.
		catch (Exception e)
		    // Output the stack trace.

After that you will need to mention the "storageConnectionString" which is the major string to create a connection to our blob in azure this helps in creation a connection to our azure account.

 public static final String storageConnectionString =
		"DefaultEndpointsProtocol=http;" +
		"AccountName=mentionYourAccountName;" +

with the help of this above example you will able to create azure blob with the name "catalog". 

If you find any issues/Queries don't hesitate to ask ur queries in the comment section below.



About Author

Author Image
Chetan Hallan

Chetan is a bright Full Stack Java Developer, he has expertise in JAVA, Spring, Hibernate, AngularJS and MySQL.

Request for Proposal

Name is required

Comment is required

Sending message..