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
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.
430
430
431
+
::: zone pivot="blob-storage-quickstart-scratch"
432
+
431
433
Add this code to the end of the `Main` method:
432
434
435
+
::: zone-end
436
+
433
437
```java
434
438
// Retrieve the connection string for use with the application.
@@ -448,39 +452,45 @@ BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
448
452
449
453
### Create a container
450
454
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.
455
456
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.
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).
463
466
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
+
464
470
### Upload blobs to a container
465
471
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.
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.
To learn more about uploading blobs, and to explore more code samples, see [Upload a blob with Java](storage-blob-upload-java.md).
477
483
478
484
### List the blobs in a container
479
485
480
486
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.
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
489
499
490
500
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.
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
501
515
502
516
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.
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).
509
527
528
+
::: zone pivot="blob-storage-quickstart-scratch"
529
+
510
530
## Run the code
511
531
512
532
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
566
586
567
587
Before you begin the cleanup process, check your *data* folder for the two files. You can compare them and observe that they're identical.
568
588
589
+
::: zone-end
590
+
569
591
## Clean up resources
570
592
593
+
::: zone pivot="blob-storage-quickstart-scratch"
594
+
571
595
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.
572
596
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
+
573
611
## Next steps
574
612
575
613
In this quickstart, you learned how to upload, download, and list blobs using Java.
0 commit comments