3

I have uploaded the files on azure blob container but how can I get the url of a that uploaded file using java. I have connectionString of the azure portal.

Can anyone help me?

2 Answers 2

6

Here I use the Azure Blob storage v12, you could refer to the below code. Further more information about this SDK you could check this source code:Azure Storage Blob client library for Java.

        String connectStr = "storage account connection";

        // Create a BlobServiceClient object which will be used to create a container client
        BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();

        BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient("container name");

        BlobClient blobClient=containerClient.getBlobClient("blob name");

        System.out.println(blobClient.getBlobUrl());

enter image description here

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

1 Comment

but what if my blob is not public and I want to create a SAS url.
0

You can try

 String blobKey = <key to your blob> 
 // Create a blob service client
 CloudBlobClient blobClient = account.createCloudBlobClient();

 CloudBlobContainer container = blobClient.getContainerReference(name);

 // get reference to the Blob you want to generate the SAS for:
 CloudBlockBlob blob = container.getBlockBlobReference(blobKey);

and call

blob.getUri();

6 Comments

but what is container?
Container client
I am trying by doing something "BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);" but it is not working can you post the complete function.
Can you please elaborate how to use container client?
but in updated answer there is a problem with "account.createCloudBlobClient()". the account object is not defined
|

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.