Skip to content

Commit 8e0612c

Browse files
progress
1 parent e2cdae7 commit 8e0612c

File tree

1 file changed

+114
-5
lines changed

1 file changed

+114
-5
lines changed

articles/storage/blobs/storage-quickstart-blobs-java.md

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,42 @@ description: In this quickstart, you learn how to use the Azure Blob Storage cli
44
author: pauljewellmsft
55
ms.author: pauljewell
66
ms.custom: devx-track-java, mode-api, passwordless-java, devx-track-extended-java
7-
ms.date: 10/24/2022
7+
ms.date: 02/28/2024
88
ms.service: azure-blob-storage
99
ms.topic: quickstart
1010
ms.devlang: java
11+
zone_pivot_groups: azure-blob-storage-quickstart-options
1112
---
1213

1314
# Quickstart: Azure Blob Storage client library for Java
1415

15-
Get started with the Azure Blob Storage client library for Java to manage blobs and containers. Follow these steps to install the package and try out example code for basic tasks.
16+
::: zone pivot="blob-storage-quickstart-scratch"
17+
18+
> [!NOTE]
19+
> The **Build from scratch** option walks you step by step through the process of creating a new project, installing packages, writing the code, and running a basic console app. This approach is recommended if you want to understand all the details involved in creating an app that connects to Azure Blob Storage. If you prefer to automate deployment tasks and start with a completed project, choose [Start with a template](storage-quickstart-blobs-java.md?pivots=blob-storage-quickstart-template).
20+
21+
::: zone-end
22+
23+
::: zone pivot="blob-storage-quickstart-template"
24+
25+
> [!NOTE]
26+
> The **Start with a template** option uses the Azure Developer CLI to automate deployment tasks and starts you off with a completed project. This approach is recommended if you want to explore the code as quickly as possible without going through the setup tasks. If you prefer step by step instructions to build the app, choose [Build from scratch](storage-quickstart-blobs-java.md?pivots=blob-storage-quickstart-scratch).
27+
28+
::: zone-end
29+
30+
Get started with the Azure Blob Storage client library for Java to manage blobs and containers.
31+
32+
::: zone pivot="blob-storage-quickstart-scratch"
33+
34+
In this article, you follow steps to install the package and try out example code for basic tasks.
35+
36+
::: zone-end
37+
38+
::: zone pivot="blob-storage-quickstart-template"
39+
40+
In this article, you use the [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) to deploy Azure resources and run a completed console app with just a few commands.
41+
42+
::: zone-end
1643

1744
> [!TIP]
1845
> If you're working with Azure Storage resources in a Spring application, we recommend that you consider [Spring Cloud Azure](/azure/developer/java/spring-framework/) as an alternative. Spring Cloud Azure is an open-source project that provides seamless Spring integration with Azure services. To learn more about Spring Cloud Azure, and to see an example using Blob Storage, see [Upload a file to an Azure Storage Blob](/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage).
@@ -21,13 +48,28 @@ Get started with the Azure Blob Storage client library for Java to manage blobs
2148

2249
## Prerequisites
2350

24-
- 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).
51+
::: zone pivot="blob-storage-quickstart-scratch"
52+
53+
- 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)
2554
- Azure Storage account - [create a storage account](../common/storage-account-create.md).
26-
- [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above.
27-
- [Apache Maven](https://maven.apache.org/download.cgi).
55+
- [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above
56+
- [Apache Maven](https://maven.apache.org/download.cgi)
57+
58+
::: zone-end
59+
60+
::: zone pivot="blob-storage-quickstart-template"
61+
62+
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
63+
- [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above
64+
- [Apache Maven](https://maven.apache.org/download.cgi)
65+
- [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd)
66+
67+
::: zone-end
2868

2969
## Setting up
3070

71+
::: zone pivot="blob-storage-quickstart-scratch"
72+
3173
This section walks you through preparing a project to work with the Azure Blob Storage client library for Java.
3274

3375
### Create the project
@@ -173,6 +215,73 @@ public class App
173215
}
174216
```
175217

218+
::: zone-end
219+
220+
::: zone pivot="blob-storage-quickstart-template"
221+
222+
With [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) installed, you can create a storage account and run the sample code with just a few commands. You can run the project in your local development environment, or in a [DevContainer](https://code.visualstudio.com/docs/devcontainers/containers).
223+
224+
### Initialize the Azure Developer CLI template and deploy resources
225+
226+
From an empty directory, follow these steps to initialize the `azd` template, provision Azure resources, and get started with the code:
227+
228+
- Clone the quickstart repository assets from GitHub and initialize the template locally:
229+
230+
```console
231+
azd init --template blob-storage-quickstart-java
232+
```
233+
234+
You'll be prompted for the following information:
235+
236+
- **Environment name**: This value is used as a prefix for all Azure resources created by Azure Developer CLI. The name must be unique across all Azure subscriptions and must be between 3 and 24 characters long. The name can contain numbers and lowercase letters only.
237+
238+
- Log in to Azure:
239+
240+
```console
241+
azd auth login
242+
```
243+
- Provision and deploy the resources to Azure:
244+
245+
```console
246+
azd up
247+
```
248+
249+
You'll be prompted for the following information:
250+
251+
- **Subscription**: The Azure subscription that your resources are deployed to.
252+
- **Location**: The Azure region where your resources are deployed.
253+
254+
The deployment might take a few minutes to complete. The output from the `azd up` command includes the name of the newly created storage account, which you'll need later to run the code.
255+
256+
## Run the sample code
257+
258+
At this point, the resources are deployed to Azure and the code is almost ready to run. Follow these steps to update the name of the storage account in the code, and run the sample console app:
259+
260+
- **Update the storage account name**:
261+
1. In the local directory, navigate to the *blob-quickstart/src/main/java/com/blobs/quickstart* directory.
262+
1. Open the file named **App.java** in your editor. Find the `<storage-account-name>` placeholder and replace it with the actual name of the storage account created by the `azd up` command.
263+
1. Save the changes.
264+
- **Run the project**:
265+
1. Navigate to the *blob-quickstart* directory containing the `pom.xml` file. Compile the project by using the following `mvn` command:
266+
```console
267+
mvn compile
268+
```
269+
1. Package the compiled code in its distributable format:
270+
```console
271+
mvn package
272+
```
273+
1. Run the following `mvn` command to execute the app:
274+
```console
275+
mvn exec:java
276+
```
277+
- **Observe the output**: This app creates a test file in your local *data* folder and uploads it to a container in the storage account. The example then lists the blobs in the container and downloads the file with a new name so that you can compare the old and new files.
278+
279+
To learn more about how the sample code works, see [Code examples](#code-examples).
280+
281+
When you're finished testing the code, see the [Clean up resources](#clean-up-resources) section to delete the resources created by the `azd up` command.
282+
283+
::: zone-end
284+
176285
## Object model
177286

178287
Azure Blob Storage is optimized for storing massive amounts of unstructured data. Unstructured data doesn't adhere to a particular data model or definition, such as text or binary data. Blob storage offers three types of resources:

0 commit comments

Comments
 (0)