This folder contains a Java application example that handles Blob storage on Microsoft Azure.
Create a new Blob Storage container in an Azure storage account.
-
You must have a Microsoft Azure subscription.
-
You must have the following installed:
- Java Development Kit (JDK) 8
- Apache Maven 3
- Azure CLI
-
The code was written for:
- Java 8
- Apache Maven 3
- Azure SDK for Java: New Client Libraries (Azure Blob Storage library v12) (com.azure)
-
Sign in Azure (Interactively).
The Azure CLI's default authentication method for logins uses a web browser and access token to sign in.
-
Run the Azure CLI login command.
az login
If the CLI can open your default browser, it will do so and load an Azure sign-in page.
Otherwise, open a browser page at https://aka.ms/devicelogin and enter the authorization code displayed in your terminal.
If no web browser is available or the web browser fails to open, use device code flow with az login --use-device-code.
-
Sign in with your account credentials in the browser.
Make sure you select your subscription by:
az account set --subscription <name or id>
-
-
Create a storage account.
An Azure storage account contains all of your Azure Storage data objects: blobs, file shares, queues, tables, and disks. The storage account provides a unique namespace for your Azure Storage data that's accessible from anywhere in the world over HTTP or HTTPS. Data in your storage account is durable and highly available, secure, and massively scalable.
An storage account can content containers and every container can content blobs.
Storage Account ├── Container_1/ │ ├── Blob_1_1/ │ └── Blob_1_2/ │ └── Container_2/ ├── Blob_2_1/ ├── Blob_2_2/ └── Blob_2_3/
Create a storage account using the Azure portal:
- Select the
Storage account
option and chooseCreate
. - Select the
Subscription
in which you want to create the new storage account. - Select the
Resource Group
for your storage account. - Enter a
name
for your storage account. - Select the
Region
for your storage account. - Select the
Performance
to be used. - Select the
Redundancy
to be used. - Click
Create
to create the storage account.
- Select the
-
Configure your application.
A connection string includes the authentication information required for your application to access data in an Azure Storage account at runtime.
Your application needs to access the connection string at runtime to authorize requests made to Azure Storage.
You can find your storage account's connection strings in the Azure portal:
- Navigate to
Storage Account
. - Select your storage account.
- Select
Access keys
and you can see your Storage account name, connection strings and account keys.
The connection string looks like this:
DefaultEndpointsProtocol=https;AccountName=<ACCOUNT_NAME>;AccountKey=<ACCOUNT_KEY>;EndpointSuffix=core.windows.net
The application configuration is stored in the
app.properties
properties file, located in the pathsrc/main/resources
. The file content is:StorageAccountConnectionString=<STORAGE_ACCOUNT_CONNECTION_STRING>
You must edit the
app.properties
file and replace the values of:<STORAGE_ACCOUNT_CONNECTION_STRING>
by the connection string of your storage account.
The application uses this information for accessing your Azure storage account.
- Navigate to
-
Run the code.
You must provide 1 parameter, replace the value of:
<CONTAINER_NAME>
by name of the container.
Run application:
java -jar azureblobstoragecreate.jar <CONTAINER_NAME>
-
Test the application.
You should see the new Blob Storage container created in an Azure storage account.