Skip to content

Commit 98630e8

Browse files
committed
init commit for storage-quickstart-blobs-java-quarkus.md
Signed-off-by: Jianguo Ma <[email protected]>
1 parent fda9392 commit 98630e8

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ items:
3838
href: storage-quickstart-blobs-java.md
3939
- name: Spring
4040
href: /azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage?toc=/azure/storage/blobs/toc.json
41+
- name: Quarkus
42+
href: storage-quickstart-blobs-java-quarkus.md
4143
- name: Python
4244
href: storage-quickstart-blobs-python.md
4345
- name: JavaScript

articles/storage/blobs/index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ landingContent:
109109
url: storage-quickstart-blobs-java.md
110110
- text: Azure Blob Storage for Spring
111111
url: /azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage?toc=/azure/storage/blobs/toc.json
112+
- text: Azure Blob Storage for Quarkus
113+
url: storage-quickstart-blobs-java-quarkus.md
112114
- text: Azure Blob Storage for Python
113115
url: storage-quickstart-blobs-python.md
114116
- text: Azure Blob Storage for JavaScript using Node.js
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: "Quickstart: Quarkus extension for Azure Blob Storage"
3+
description: In this quickstart, you learn how to use the Quarkus extension for Azure Blob Storage to create a container and a blob in Blob (object) storage. Next, you learn how to download the blob to your local computer, and how to list all of the blobs in a container.
4+
author: KarlErickson
5+
ms.author: jiangma
6+
ms.custom: devx-track-java, mode-api, passwordless-java, devx-track-extended-java, devx-track-extended-azdevcli, devx-track-javaee-quarkus, devx-track-javaee-quarkus-storage-blob
7+
ms.date: 01/15/2025
8+
ms.service: azure-blob-storage
9+
ms.topic: quickstart
10+
ms.devlang: java
11+
---
12+
13+
# Quickstart: Quarkus extension for Azure Blob Storage
14+
15+
Get started with the Quarkus extension for Azure Blob Storage to manage blobs and containers. In this article, you follow steps to try out example code for basic tasks.
16+
17+
[Reference documentation](https://docs.quarkiverse.io/quarkus-azure-services/dev/quarkus-azure-storage-blob.html) | [Library source code](https://github.com/quarkiverse/quarkus-azure-services/tree/main/services/azure-storage-blob) | [Package (Maven)](https://mvnrepository.com/artifact/io.quarkiverse.azureservices/quarkus-azure-storage-blob) | [Sample](https://github.com/quarkiverse/quarkus-azure-services/tree/main/integration-tests/azure-storage-blob)
18+
19+
## Prerequisites
20+
21+
- Azure account with an active subscription - [create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio)
22+
- Azure Storage account - [create a storage account](../common/storage-account-create.md).
23+
- [Java Development Kit (JDK)](/java/azure/jdk/) version 17 or above
24+
- [Apache Maven](https://maven.apache.org/download.cgi)
25+
26+
## Setting up
27+
28+
This section walks you through preparing a project to work with the Quarkus extensions for Azure Blob Storage.
29+
30+
### Download the sample application
31+
32+
The [sample application](https://github.com/Azure-Samples/quarkus-azure/tree/2025-01-16/storage-blob-quarkus) used in this quickstart is a basic Quarkus application.
33+
34+
Use [git](https://git-scm.com/) to download a copy of the application to your development environment, and navigate to the `storage-blob-quarkus` directory.
35+
36+
```bash
37+
git clone https://github.com/Azure-Samples/quarkus-azure.git
38+
cd quarkus-azure
39+
git checkout 2025-01-16
40+
cd storage-blob-quarkus
41+
```
42+
43+
## Authenticate to Azure and authorize access to blob data
44+
45+
Application requests to Azure Blob Storage must be authorized. Using `DefaultAzureCredential` and the Azure Identity client library is the recommended approach for implementing passwordless connections to Azure services in your code, including Blob Storage. The Quarkus extension for Azure services supports this approach.
46+
47+
`DefaultAzureCredential` is a credential chain implementation provided by the Azure Identity client library for Java. `DefaultAzureCredential` supports multiple authentication methods and determines which method to use at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code.
48+
49+
The order and locations in which `DefaultAzureCredential` looks for credentials can be found in the [Azure Identity library overview](/java/api/overview/azure/identity-readme#defaultazurecredential).
50+
51+
In this quickstart, your app authenticates using your Azure CLI sign-in credentials when running locally. Once it's deployed to Azure, your app can then use a [managed identity](../../active-directory/managed-identities-azure-resources/overview.md). This transition between environments doesn't require any code changes.
52+
53+
### Assign roles to your Microsoft Entra user account
54+
55+
[!INCLUDE [assign-roles](../../../includes/assign-roles.md)]
56+
57+
### Sign-in and connect your app code to Azure using DefaultAzureCredential
58+
59+
You can authorize access to data in your storage account using the following steps:
60+
61+
1. Make sure you're authenticated with the same Microsoft Entra account you assigned the role to on your storage account. The following example shows how to authenticate via the Azure CLI:
62+
63+
```azurecli
64+
az login
65+
```
66+
67+
2. Make sure you provide the endpoint of your Azure Blob Storage account. The following example shows how to set the endpoint using the environment variable `QUARKUS_AZURE_STORAGE_BLOB_ENDPOINT` via the Azure CLI. Replace `<RESOURCE_GROUP_NAME>` and `<STORAGE_ACCOUNT_NAME>` with your resource group and storage account names before running the command:
68+
69+
```azurecli
70+
export QUARKUS_AZURE_STORAGE_BLOB_ENDPOINT=$(az storage account show \
71+
--resource-group <RESOURCE_GROUP_NAME> \
72+
--name <STORAGE_ACCOUNT_NAME> \
73+
--query 'primaryEndpoints.blob' \
74+
--output tsv)
75+
```
76+
77+
> [!NOTE]
78+
> When deployed to Azure, you'll need to enable managed identity on your app, and configure your storage account to allow that managed identity to connect. For detailed instructions on configuring this connection between Azure services, see the [Auth from Azure-hosted apps](/azure/developer/java/sdk/identity-azure-hosted-auth) tutorial.
79+
80+
## Run the sample
81+
82+
The code example performs the following actions:
83+
84+
- Injects a client object that is already authorized for data access via `DefaultAzureCredential` using the Quarkus extension for Azure Blob Storage
85+
- Creates a container in a storage account
86+
- Uploads a blob to the container
87+
- Lists the blobs in the container
88+
- Downloads the blob data to the local file system
89+
- Deletes the blob and container resources created by the app
90+
91+
Run the application using the following command:
92+
93+
```bash
94+
mvn package
95+
java -jar ./target/quarkus-app/quarkus-run.jar
96+
```
97+
98+
The output of the app is similar to the following example (UUID values omitted for readability):
99+
100+
```output
101+
Uploading to Blob storage as blob:
102+
https://mystorageacct.blob.core.windows.net/quickstartblobsUUID/quickstartUUID.txt
103+
104+
Listing blobs...
105+
quickstartUUID.txt
106+
107+
Downloading blob to
108+
./data/quickstartUUIDDOWNLOAD.txt
109+
110+
Press the Enter key to begin clean up
111+
112+
Deleting blob container...
113+
Deleting the local source and downloaded files...
114+
Done
115+
```
116+
117+
Before you begin the cleanup process, check your data folder for the two files. You can compare them and observe that they're identical.
118+
119+
## Understand the sample code
120+
121+
Next, you walk through the sample code to understand how it works.
122+
123+
## Next step
124+
125+
> [!div class="nextstepaction"]
126+
> [Azure Storage samples and developer guides for Java](../common/storage-samples-java.md?toc=/azure/storage/blobs/toc.json)

0 commit comments

Comments
 (0)