4
votes

I know that we can upload files to azure blob storage using below:

        CloudBlockBlob cloudBlockBlob = fileContainer.GetBlockBlobReference(fileName);
        await cloudBlockBlob.UploadFromFileAsync(fileFullPath);

I already created some folders in the container. I tried a few time but the files always uploaded outside the folder.

How do we upload the files into a specific folder in the blob storage?

2

2 Answers

5
votes

I guess you have to get the right reference first ( you need to include the fullpath of the file in the GetBlockBlobReference) as in :

 CloudBlockBlob cloudBlockBlob = fileContainer.GetBlockBlobReference($"yourfoldername/{fileName}");

One important thing is you DON'T need to create folder, it will automatically create it for you based on your path in the GetBlockBlobReference.

5
votes

Actually there aren't real folders in Azure Blob Storage, it's just a virtual concept. In other words, Azure Blob Storage only has simple 2-level "container - blob" structure, the so-called "folders" are just prefixes of existing blob names.

For example, if there is a blob named a/b/c.jpg. The a and b are virtual folder names, you can't directly create or delete them, they exist there just because of blob a/b/c.jpg.