Skip to content

Commit f1861f6

Browse files
Edits
1 parent 8a7e254 commit f1861f6

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

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

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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: 02/28/2024
7+
ms.date: 03/04/2024
88
ms.service: azure-blob-storage
99
ms.topic: quickstart
1010
ms.devlang: java
@@ -428,8 +428,12 @@ export AZURE_STORAGE_CONNECTION_STRING="<yourconnectionstring>"
428428

429429
The code below retrieves the connection string for the storage account from the environment variable created earlier, and uses the connection string to construct a service client object.
430430

431+
::: zone pivot="blob-storage-quickstart-scratch"
432+
431433
Add this code to the end of the `Main` method:
432434

435+
::: zone-end
436+
433437
```java
434438
// Retrieve the connection string for use with the application.
435439
String connectStr = System.getenv("AZURE_STORAGE_CONNECTION_STRING");
@@ -448,39 +452,45 @@ BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
448452

449453
### Create a container
450454

451-
Decide on a name for the new container. The code below appends a UUID value to the container name to ensure that it's unique.
452-
453-
> [!IMPORTANT]
454-
> Container names must be lowercase. For more information about naming containers and blobs, see [Naming and Referencing Containers, Blobs, and Metadata](/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata).
455+
Create a new container in your storage account by creating an instance of the [BlobContainerClient](/java/api/com.azure.storage.blob.blobcontainerclient) class and calling the [create](/java/api/com.azure.storage.blob.blobcontainerclient.create) method. In this example, the code appends a GUID value to the container name to ensure that it's unique.
455456

456-
Next, create an instance of the [BlobContainerClient](/java/api/com.azure.storage.blob.blobcontainerclient) class, then call the [create](/java/api/com.azure.storage.blob.blobcontainerclient.create) method to actually create the container in your storage account.
457+
::: zone pivot="blob-storage-quickstart-scratch"
457458

458459
Add this code to the end of the `Main` method:
459460

461+
::: zone-end
462+
460463
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_CreateContainer":::
461464

462465
To learn more about creating a container, and to explore more code samples, see [Create a blob container with Java](storage-blob-container-create-java.md).
463466

467+
> [!IMPORTANT]
468+
> Container names must be lowercase. For more information about naming containers and blobs, see [Naming and Referencing Containers, Blobs, and Metadata](/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata).
469+
464470
### Upload blobs to a container
465471

466-
Add this code to the end of the `Main` method:
472+
Upload a blob to a container by calling the [uploadFromFile](/java/api/com.azure.storage.blob.blobclient.uploadfromfile) method. The example code creates a text file in the local *data* directory to upload to the container.
467473

468-
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_UploadBlobFromFile":::
474+
::: zone pivot="blob-storage-quickstart-scratch"
475+
476+
Add this code to the end of the `Main` method:
469477

470-
The code snippet completes the following steps:
478+
::: zone-end
471479

472-
1. Creates a text file in the local *data* directory.
473-
1. Gets a reference to a [BlobClient](/java/api/com.azure.storage.blob.blobclient) object by calling the [getBlobClient](/java/api/com.azure.storage.blob.blobcontainerclient.getblobclient) method on the container from the [Create a container](#create-a-container) section.
474-
1. Uploads the local text file to the blob by calling the [uploadFromFile](/java/api/com.azure.storage.blob.blobclient.uploadfromfile) method. This method creates the blob if it doesn't already exist, but won't overwrite it if it does.
480+
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_UploadBlobFromFile":::
475481

476482
To learn more about uploading blobs, and to explore more code samples, see [Upload a blob with Java](storage-blob-upload-java.md).
477483

478484
### List the blobs in a container
479485

480486
List the blobs in the container by calling the [listBlobs](/java/api/com.azure.storage.blob.blobcontainerclient.listblobs) method. In this case, only one blob has been added to the container, so the listing operation returns just that one blob.
481487

488+
::: zone pivot="blob-storage-quickstart-scratch"
489+
482490
Add this code to the end of the `Main` method:
483491

492+
::: zone-end
493+
484494
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_ListBlobs":::
485495

486496
To learn more about listing blobs, and to explore more code samples, see [List blobs with Java](storage-blobs-list-java.md).
@@ -489,8 +499,12 @@ To learn more about listing blobs, and to explore more code samples, see [List b
489499

490500
Download the previously created blob by calling the [downloadToFile](/java/api/com.azure.storage.blob.specialized.blobclientbase.downloadtofile) method. The example code adds a suffix of "DOWNLOAD" to the file name so that you can see both files in local file system.
491501

502+
::: zone pivot="blob-storage-quickstart-scratch"
503+
492504
Add this code to the end of the `Main` method:
493505

506+
::: zone-end
507+
494508
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_DownloadBlob":::
495509

496510
To learn more about downloading blobs, and to explore more code samples, see [Download a blob with Java](storage-blob-download-java.md).
@@ -501,12 +515,18 @@ The following code cleans up the resources the app created by removing the entir
501515

502516
The app pauses for user input by calling `System.console().readLine()` before it deletes the blob, container, and local files. This is a good chance to verify that the resources were created correctly, before they're deleted.
503517

518+
::: zone pivot="blob-storage-quickstart-scratch"
519+
504520
Add this code to the end of the `Main` method:
505521

522+
::: zone-end
523+
506524
:::code language="java" source="~/azure-storage-snippets/blobs/quickstarts/Java/blob-quickstart/src/main/java/com/blobs/quickstart/App.java" id="Snippet_DeleteContainer":::
507525

508526
To learn more about deleting a container, and to explore more code samples, see [Delete and restore a blob container with Java](storage-blob-container-delete-java.md).
509527

528+
::: zone pivot="blob-storage-quickstart-scratch"
529+
510530
## Run the code
511531

512532
This app creates a test file in your local folder and uploads it to Blob storage. 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.
@@ -566,10 +586,28 @@ Done
566586

567587
Before you begin the cleanup process, check your *data* folder for the two files. You can compare them and observe that they're identical.
568588

589+
::: zone-end
590+
569591
## Clean up resources
570592

593+
::: zone pivot="blob-storage-quickstart-scratch"
594+
571595
After you've verified the files and finished testing, press the **Enter** key to delete the test files along with the container you created in the storage account. You can also use [Azure CLI](storage-quickstart-blobs-cli.md#clean-up-resources) to delete resources.
572596

597+
::: zone-end
598+
599+
::: zone pivot="blob-storage-quickstart-template"
600+
601+
When you're done with the quickstart, you can clean up the resources you created by running the following command:
602+
603+
```console
604+
azd down
605+
```
606+
607+
You'll be prompted to confirm the deletion of the resources. Enter `y` to confirm.
608+
609+
::: zone-end
610+
573611
## Next steps
574612

575613
In this quickstart, you learned how to upload, download, and list blobs using Java.

0 commit comments

Comments
 (0)