Get started using Azure Storage with Java
In this sample, you will find the following folders:
- storage-blobs-java-v10-quickstart-v11 - references Storage Blobs SDK v11.0.0
- storage-blobs-java-v10-quickstart-v12 - references Storage Blobs SDK v12.0.0
If you don't have an Azure subscription, create a free account before you begin.
Create a Storage Account using the Azure portal
Step 1 : Create a new general-purpose storage account to use for this tutorial.
- Go to the Azure Portal and log in using your Azure account.
- Select New > Storage > Storage account.
- Select your Subscription.
Resource group, create a new one and give it a unique name.
- Enter a name for your storage account.
- Select the
Locationto use for your Storage Account.
Account kindto StorageV2(general purpose v2).
Replicationto Locally-redundant storage (LRS).
Secure transfer requiredto Disabled.
- Check Review + create and click Create to create your Storage Account.
Step 2 : Copy and save keys.
- After your Storage Account is created. Click on it to open it. Select Settings > Access keys > key1/key2, Select a key and copy the Key to the clipboard, then paste it into text editor for later use.
Set credentials in environment variables
export AZURE_STORAGE_ACCOUNT="<YourAccountName>" export AZURE_STORAGE_ACCESS_KEY="<YourAccountKey>"
setx AZURE_STORAGE_ACCOUNT "<YourAccountName>" setx AZURE_STORAGE_ACCESS_KEY "<YourAccountKey>"
At this point, you can run this application using maven:
mvn compile exec:java. It creates its own file to upload and download, and then cleans up after itself by deleting everything at the end.
mvn compile exec:java
This Quickstart shows how to do the following operations of Storage Blobs.
- Create a Storage Account using the Azure portal.
- Create a container.
- Upload a file to block blob.
- List blobs.
- Download a blob to file.
- Delete a blob.
- Delete the container.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.