You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2015/04/30 08:24:45 UTC

jclouds-site git commit: Update azure-storage.md

Repository: jclouds-site
Updated Branches:
  refs/heads/master d420213f3 -> 7dc237752


Update azure-storage.md

Corrected link to Azure portal
Corrected instructions as they were not fully correct.
Aligned code to jclouds version 1.9.0 and removed deprecated methods. For example, createInputStreamMap() was deprecated in version 1.6.0


Project: http://git-wip-us.apache.org/repos/asf/jclouds-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-site/commit/7dc23775
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-site/tree/7dc23775
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-site/diff/7dc23775

Branch: refs/heads/master
Commit: 7dc23775245b6754aff0cc2910030b8182c16cca
Parents: d420213
Author: ANKUR PRAKASH GARGI <an...@gmail.com>
Authored: Wed Apr 29 23:11:43 2015 +0530
Committer: Andrew Gaul <ga...@apache.org>
Committed: Wed Apr 29 23:24:36 2015 -0700

----------------------------------------------------------------------
 guides/azure-storage.md | 64 +++++++++++++++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-site/blob/7dc23775/guides/azure-storage.md
----------------------------------------------------------------------
diff --git a/guides/azure-storage.md b/guides/azure-storage.md
index 8b21d06..12b098f 100644
--- a/guides/azure-storage.md
+++ b/guides/azure-storage.md
@@ -6,37 +6,63 @@ permalink: /guides/azure-storage/
 
 1. Sign up for an [Azure Account](http://www.microsoft.com/windowsazure/offers/)
 2. Get your account and key
-	* Login to the [Windows Azure Portal](http://windows.azure.com)
-	* Click New Project, and then select Storage Account.
-	* Enter a project label and click Next.
-	* Enter the same name for the Storage Account Name. Make sure the account is available and then click _Create_
-		* This is your account in jclouds.
-	* Under the main azure screen, you should see Cloud Storage and the service you setup; Click on that.
+	* Login to the [Microsoft Azure Portal](https://manage.windowsazure.com). The [new portal](https://portal.azure.com) 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](/start/install).
-5. Start coding
+5. Setup your project to include 'guava'. Include following dependency to jclouds [Installation](/start/install). Update the version mentioned in dependency below to the latest available version.
+	<dependency>
+		<groupId>com.google.guava</groupId>
+		<artifactId>guava</artifactId>
+		<version>16.0</version>
+	</dependency>
+6. Start coding. Replace values in angular brackets <> with actual values.
 
 {% highlight java %}
-import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Builder.withPublicAcl;
+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.*;
 
-// get a context with amazon that offers the portable BlobStore api
+String storageAccountName = "<Your storage account name>";
+String storageAccountKey = "<Your storage account primary access key>";
+String containerName = "<Your container name>";
+String blobFullyQualifiedFileName = "<Fully qualified filename>";
+String blobName = "<Your blob name>";
+
+// Get a context with amazon that offers the portable BlobStore api
 BlobStoreContext context = ContextBuilder.newBuilder("azureblob")
-                 .credentials(accesskeyid, secretkey)
-                 .buildView(BlobStoreContext.class);
+				 .credentials(storageAccountName, storageAccountKey)
+				 .buildView(BlobStoreContext.class);
+
+// Access the BlobStore
+BlobStore blobStore = context.getBlobStore();
 
-//create a container in the default location
-context.getBlobStore().createContainerInLocation(null, bucket);
+// Create a Container
+blobStore.createContainerInLocation(null, containerName);
 
-// use the map interface for easy access to put/get things, keySet, etc.
-context.createInputStreamMap(bucket).put("blob.txt", inputStream);
+// Create a blob. 
+ByteSource payload = Files.asByteSource(new File(blobFullyQualifiedFileName));
+Blob blob = context.getBlobStore().blobBuilder(blobName)
+	.payload(payload)  // or InputStream
+	.contentLength(payload.size())
+	.build();
 
-// when you need access to azureblob-specific features, use the provider-specific context
-AzureBlobClient client = AzureBlobClient.class.cast(context.getProviderSpecificContext().getApi());
+// Upload the Blob
+blobStore.putBlob(containerName, blob);
 
-// create a root-level container with a public acl
-client.createRootContainer(withPublicAcl());
+// 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 %}