layout: page title: “Azure Storage Service: Getting Started Guide” permalink: /guides/azure-storage/

  1. Sign up for an Azure Account
  2. Get your account and key
    • Login to the Microsoft Azure Portal. The new portal is in preview stage and hence instructions are not aligned with it.
    • Click ‘New’, ‘Data Servies’, ‘Storage’ and ‘Quick Create’.
    • Enter the Storage Account Name. Make sure the account is available and then click Create
      • This is your Storage account name you use in jclouds.
    • Under the main Azure screen, you should see Cloud Storage and the service you setup; Click on that.
    • Click on ‘Manage Access Keys’ at bottom of the page and copy Primary Access Key.
      • Primary Access Key is the key you use in jclouds
  3. Ensure you are using a recent JDK 6
  4. Setup your project to include azureblob
    • Get the dependency org.apache.jclouds.provider/azureblob using jclouds Installation.
  5. Setup your project to include ‘guava’. Include following dependency to jclouds Installation. Update the version mentioned in dependency below to the latest available version. com.google.guava guava 16.0
  6. Start coding. Replace values in angular brackets <> with actual values.

{% highlight java %} import org.jclouds.blobstore.; import org.jclouds.ContextBuilder; import org.jclouds.blobstore.domain.; import org.jclouds.azureblob.; import com.google.common.io.; import java.io.*;

String storageAccountName = “”; String storageAccountKey = “”; String containerName = “”; String blobFullyQualifiedFileName = “”; String blobName = “”;

// Get a context with amazon that offers the portable BlobStore api BlobStoreContext context = ContextBuilder.newBuilder(“azureblob”) .credentials(storageAccountName, storageAccountKey) .buildView(BlobStoreContext.class);

// Access the BlobStore BlobStore blobStore = context.getBlobStore();

// Create a Container blobStore.createContainerInLocation(null, containerName);

// Create a blob. ByteSource payload = Files.asByteSource(new File(blobFullyQualifiedFileName)); Blob blob = context.getBlobStore().blobBuilder(blobName) .payload(payload) // or InputStream .contentLength(payload.size()) .build();

// Upload the Blob blobStore.putBlob(containerName, blob);

// When you need access to azureblob-specific features, use the provider-specific context AzureBlobClient azureBlobClient = context.unwrapApi(AzureBlobClient.class); Object object = azureBlobClient.getBlobProperties(containerName, blobName);

System.out.println("Object: " + object); context.close(); {% endhighlight %}