How to read content of azure blob with url for each static file uploaded
Posted By : Chetan Hallan | 30-Sep-2015
In this blog we will learn about how we can read content from our azure blob. If you are not familiar with azure blob then you can refer to my previous posts How to create an azure blob from grails application and If you don't know how to upload any static file in azure storage then first go through this link to get the brief idea about how azure works How to upload a static file in azure blob from grails application
To read all the content from your azure blob you can use the following code.
Pre-requisite:-
- You have created an azure blob successfully.
- Uploaded some static files in the blob storage.
public void read(){
try
{
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
System.out.println("connection established");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
System.out.println("client created"+blobClient.getStorageUri());
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.getContainerReference("catalog");
System.out.println("referrence fetch"+container.getName());
// Loop over blobs within the container and output the URI to each of them.
System.out.println("elements"+container.listBlobs());
for (ListBlobItem blobItem : container.listBlobs()) {
System.out.println(blobItem.getUri());
}
}
catch (Exception e)
{
// Output the stack trace.
e.printStackTrace();
}
}
With the help of the above code you will get a list of all the files of ur all static files uploaded in the azure blob with their url's.
For any further Queries and Questions you can contact me via comments. Feel free to comment and ask.
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Chetan Hallan
Chetan is a bright Full Stack Java Developer, he has expertise in JAVA, Spring, Hibernate, AngularJS and MySQL.