Skip to content

Azure java with maven.

March 27, 2012

I am writing small java client application to upload large files to azure blob storage. So I started with setting up sample java project using maven. It is very basic stuff, still I am going ahead and dumping it here.

mvn archetype:generate -DgroupId=com.sample.cloud -DartifactId=upload-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

You need to add maven dependency in your pom file

        <dependency>
            <groupId>com.microsoft.windowsazure</groupId>
            <artifactId>microsoft-windowsazure-api</artifactId>
            <version>0.2.0</version>
        </dependency>

now you are ready to roll.

I wanted to upload the big file in parallel and fortunately java azure SDK provide built in capability to upload the blob using multiple thread to avoid latency. Below is code snip to show that.

CloudBlobClient cloudBlobClient = storageaccount
.createCloudBlobClient();

//thread count
cloudBlobClient.setConcurrentRequestCount(5);
cloudBlobClient.setSingleBlobPutThresholdInBytes(64* Constants.MB);
//create container if it does not exist
CloudBlobContainer uploadLoc = cloudBlobClient.getContainerReference(“mycontainer”);
uploadLoc.createIfNotExist();
CloudBlockBlob blockBlob = uploadLoc.getBlockBlobReference(file.getName());
blockBlob.upload(new FileInputStream(file), file.length());

for details refer to the link below.

http://msdn.microsoft.com/en-us/library/windowsazure/hh690953%28vs.103%29.aspx

Advertisements

From → Tech

Leave a Comment

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: