0

Just trying to familiarise and understand the following tutorial on how to access the blobs using Java :- https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-java?tabs=powershell%2Cmanaged-identity%2Croles-azure-portal%2Csign-in-azure-cli

I am familiar with Java but not Azure Blob Storage. I have some basic questions around the API that I hope someone will be able to clarify :-

• A “data” folder is created and this folder is where the blob data files will be created and stored. I presume what this is really saying is that the downloaded blobs will be “saved” to the “data” folder. The actual storage of the blob is still in the Azure cloud. Is my understanding correct ?

• Any content downloaded to the “data” folder can be viewed as temporary area where content of blob are saved into a unique filename. The file in the “data” folder can be deleted. Should the blob content be needed again, the blob can be downloaded again to a file in data folder. ?

• Each BlobClient instance is associated with one blob ?

• The BlobClient instance can be used to upload content into blob or download the blob content ?

• The blob is identified by the filename passed when the BlobClient is created ?

• Each blob stored must be associated with unique filename ?

• The blob stored with 1st line will be over written with the content of filename by the 2nd line line 1 - blobClient.uploadFromFile(localPath + fileName); line 2 - blobClient.uploadFromFile(localPath + fileName);

The point I just wanted to confirm was that content stored by a blob can be overwritten

• The sample code is basic. However, how are difficult scenarios like concurrency handled with the API ?

I appreciate these questions might seem simple, but it important to understand the basics, before moving forward.

Thank you for any help.

Pete

1 Answer 1

3

A “data” folder is created and this folder is where the blob data files will be created and stored. I presume what this is really saying is that the downloaded blobs will be “saved” to the “data” folder. The actual storage of the blob is still in the Azure cloud. Is my understanding correct.

  1. Yes, the files which are available in the data folder will be used for uploading to the blob and the files which are downloaded from Blob will be stored in the data folder as mentioned in the code snippet.
String localPath = "./data/"; 
String fileName = "quickstart" + java.util.UUID.randomUUID() + ".txt";

enter image description here

enter image description here

Any content downloaded to the “data” folder can be viewed as temporary area where content of blob are saved into a unique filename. The file in the “data” folder can be deleted. Should the blob content be needed again, the blob can be downloaded again to a file in data folder. ?

  1. Yes, even if the files downloaded to the "data" folder is deleted, the files which are uploaded will be available in the container. If the blob content is required again, the blob can be downloaded again to the "data" folder.

enter image description here

enter image description here

Downloading the files again from the container to data folder:

enter image description here

  1. Each Blob Client instance is associated with one blob at a time. Blob Client class provides a client (Blob Service client) which contains few generic operations for Azure Storage Blobs like uploading and downloading files, copying and retrieving blobs, deleting and un-deleting a blob.

  2. Yes, Blob is the filename which is passed to the BlobClient object as shown below:

String  fileName  =  "quickstart"  +  java.util.UUID.randomUUID() +  ".txt";

// Get a reference to a blob
BlobClient  blobClient  =  blobContainerClient.getBlobClient(fileName);

System.out.println("\nUploading to Blob storage as blob:\n\t"  +  blobClient.getBlobUrl());

// Upload the blob
blobClient.uploadFromFile(localPath  +  fileName);

As mentioned in the MSDOC you have given, blobClient.uploadFromFile(localPath + fileName); verifies if the file already exists or not. If it exists, it won't be overwritten. enter image description here

  1. In the below given code, it creates a new container along with new blob:

Here, container name should be unique, and the file name can be anything. Because when we upload a file, it will be stored in separate container every time.

// Create a container with an unique name
String  containerName  =  "quickstartblobs"  +  java.util.UUID.randomUUID();

BlobContainerClient  blobContainerClient  =  blobServiceClient.createBlobContainer(containerName);

String  localPath  =  "./data/";

String  fileName  =  "quickstart"  +  java.util.UUID.randomUUID() +  ".txt";

If the container name already exists, it returns error as shown below:

enter image description here

References:

Refer to my SO Answer to achieve similar scenario using REST API.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for a comprehensive response. You went to so much effort to make the response even easier to understand. Very much appreciated. Sorry for my very late response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.