Search code examples
java-8azure-storageazure-blob-storageazure-storage-filesazure-java-sdk

Azure Storage Blob Container Vituval Folder Image Download IN JAVA


I want to download a image from Azure Storage Blob Container have virtual folder, it contain Image, need to download that image in java code.

Asure Storage Stucture:

"Blob-Container" -> "Blob-Folder" -> "Sample.jpg"

Below code is direct download image from Container, i need to download image from fodler inside the container

BlobServiceClient storageClient = new BlobServiceClientBuilder() .endpoint(endpoint.toString()) .credential(credential) .buildClient();

    BlobContainerClient blobContainer = storageClient.getBlobContainerClient(azureContainer);

    BlockBlobClient blobClient = blobContainer.getBlobClient(fileName).getBlockBlobClient();
    blobClient.download(response.getOutputStream());

Solution

  • First of all, you need to know that the storage of azure blob storage is actually flat, it actually has no so-called folders at all.

    What I mean is that you have to combine the path and file name as the filename passing method. If you list the files in the current container, you will find that they are in a form similar to this:

    folder1/folder2/filename.suffix