Emre Kara
Emre Kara

Reputation: 27

How to download a file (inside an other folder) from Azure Blob Storage?

I need to download a file from Azure Blob storage. But the file inside another folder. For example;

Blob Containers
---myBlobContainer
-----TestFolder1
-------TestFolder2
-----------aaa.jpeg

I want to download aaa.jpeg file. I can download it when the situation like below;

Blob Containers
---myBlobContainer
------aaa.jpeg

How can I navigate through the folders, I cant give a path to the file. Thanks

Upvotes: 0

Views: 1306

Answers (1)

Thiago Custodio
Thiago Custodio

Reputation: 18362

There's no folders when using Azure Storage Account. You have a container, and all the rest is part of the blob name.

e.g.

myBlobContainer/TestFolder1/TestFolder2/aaa.jpeg

myBlobContainer is the container name

/TestFolder1/TestFolder2/aaa.jpeg

is the blob name

more info: https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#blob-names

An easy way to double check this, just loop over all the blobs inside a container, you can confirm the 'sublevels' are part of the blob name

BlobContainerClient blobContainerClient = new BlobContainerClient(connectionString, container);
blobContainerClient.CreateIfNotExists();
Console.WriteLine("Listing blobs...");
// List all blobs in the container
var blobs = blobContainerClient.GetBlobs();
foreach (BlobItem blobItem in blobs)
{
     Console.WriteLine("\t" + blobItem.Name);
} 

       

Upvotes: 3

Related Questions