azureblob
org.apache.jclouds.provider/azureblob
using jclouds Installation.{% 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 %}
To use Azure Active Directory with Azure Blob storage, follow these steps:
az ad app create --display-name <name> --password <password>
az ad sp create --id <Application-id>
az role assignment create --role "Storage Blob Data Contributor" --assignee <service principal ID>
az account show
In step 2, note the Azure Application ID returned. It will be used to create the service principal. In step 3, note the service principal ID returned -- it is required in step 4 to assign the role so that the service principal can access the storage account.
Now you can use Azure Blob using Azure AD authentication. The required properties are:
jclouds.azureblob.auth=azureAd
jclouds.identity=<service principal ID>
jclouds.credential=<service principal password>
jclouds.azureblob.tenantId=<tenant ID>
jclouds.azureblob.account=<Azure Blob storage account>