3.4 KiB
title | description | keywords | author | ms.author | manager | ms.date | ms.topic | ms.prod | ms.technology | ms.devlang | ms.service |
---|---|---|---|---|---|---|---|---|---|---|---|
Azure Storage libraries for Java | Azure, Java, SDK, API, Storage | douge | seguler | dineshm | 10/29/2018 | article | azure | azure | java | storage |
Azure Storage libraries for Java
Overview
Read and write blob (object) data, files, and messages from your Java applications with Azure Storage.
To get started with Azure Storage, see How to use Blob storage from Java SDK v7.
Client library
Use a Shared Key, SAS token or an OAuth token from the Azure Active Directory to authorize with Azure Storage services. Then use the client libraries' classes and methods to work with blob, file, or queue storage.
Add a dependency to your Maven pom.xml
file to use the client library in your project.
Dependency for the legacy Azure Storage SDK v7:
<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-storage -->
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.0.0</version>
</dependency>
Example
Write an image file from the local file system into a new blob in an existing Azure Storage blob container.
// Parse the connection string and create a blob client to interact with Blob storage
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("quickstartcontainer");
// Create the container if it does not exist with public access.
container.createIfNotExists(BlobContainerPublicAccessType.CONTAINER, new BlobRequestOptions(), new OperationContext());
[!div class="nextstepaction"] Explore the Client APIs
Management API
Crete and manage Azure Storage accounts and connection keys with the management API.
Add a dependency to your Maven pom.xml
file to use the management API in your project.
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-mgmt-storage</artifactId>
<version>1.3.0</version>
</dependency
Example
Create a new Azure Storage account in your subscription and retrieve its access keys.
StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.create();
// get a list of storage account keys related to the account
List<StorageAccountKey> storageAccountKeys = storageAccount.getKeys();
for(StorageAccountKey key : storageAccountKeys) {
System.out.println("Key name: " + key.keyName() + " with value "+ key.value());
}
[!div class="nextstepaction"] Explore the Management APIs
Samples
Azure Storage SDK for Java
Read and write objects to blob storage
Read and write messages with queues