You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Azure Blob Storage client library for Java
14
15
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
16
43
17
44
> [!TIP]
18
45
> 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
21
48
22
49
## Prerequisites
23
50
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)
25
54
- Azure Storage account - [create a storage account](../common/storage-account-create.md).
26
-
-[Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above.
This section walks you through preparing a project to work with the Azure Blob Storage client library for Java.
32
74
33
75
### Create the project
@@ -173,6 +215,73 @@ public class App
173
215
}
174
216
```
175
217
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
+
176
285
## Object model
177
286
178
287
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