Windows Azure: How to create sub directory in a blob container
Windows Azure: How to create sub directory in a blob container
How to create a sub directory in a blob container
for example,
in my blob container http://veda.blob.core.windows.net/document/
If I store some files it will be
http://veda.blob.core.windows.net/document/1.txt
http://veda.blob.core.windows.net/document/2.txt
Now, how to create a sub directory
http://veda.blob.core.windows.net/document/folder/
So that I can store files
http://veda.blob.core.windows.net/document/folder/1.txt
8 Answers
8
To add on to what Egon said, simply create your blob called "folder/1.txt", and it will work. No need to create a directory.
read my answer below @afr0
– AntonB
Jan 4 '16 at 23:40
This does not work for me, says containers cant use anything but lowercase, hyphens, numbers. Same for filenames
– Green_qaue
Feb 3 '17 at 14:16
@Green_qaue you have to use only lowercase letters and numbers for naming your container/directories and that's why you got errors.
– Sapan Ghafuri
Mar 4 '17 at 9:52
it creates several directories with the same folder, I mean each time I upload file, it create directory called "folder" again , is there any method to check if folder exist so it shouldn't create it?
– amal50
May 3 at 0:34
There is actually only a single layer of containers. You can virtually create a "file-system" like layered storage, but in reality everything will be in 1 layer, the container in which it is.
For creating a virtual "file-system" like storage, you can have blob names that contain a '/' so that you can do whatever you like with the way you store. Also, the great thing is that you can search for a blob at a virtual level, by giving a partial string, up to a '/'.
These 2 things, adding a '/' to a path and a partial string for search, together create a virtual "file-system" storage.
Can you share C# sample? blob.The name is read only property so we are not able to create a blob.Name with "/"
– ABB
Aug 8 '17 at 6:47
There is a comment by @afr0 asking how to filter on folders..
There is two ways using the GetDirectoryReference or looping through a containers blobs and checking the type. The code below is in C#
GetDirectoryReference
CloudBlobContainer container = blobClient.GetContainerReference("photos");
//Method 1. grab a folder reference directly from the container
CloudBlobDirectory folder = container.GetDirectoryReference("directoryName");
//Method 2. Loop over container and grab folders.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlobDirectory))
{
// we know this is a sub directory now
CloudBlobDirectory subFolder = (CloudBlobDirectory)item;
Console.WriteLine("Directory: {0}", subFolder.Uri);
}
}
read this for more in depth coverage: http://www.codeproject.com/Articles/297052/Azure-Storage-Blobs-Service-Working-with-Directori
This should be the answer as of today's date. +1
– MickyD
Feb 13 '17 at 4:04
In Azure Portal we have below option while uploading file :

If you use Microsoft Azure Storage Explorer, there is a "New Folder" button that allows you to create a folder in a container.
This is actually a virtual folder:

Here's how i do it in CoffeeScript on Node.JS:
blobService.createBlockBlobFromText 'containerName', (path + '$$$.$$$'), '', (err, result)->
if err
console.log 'failed to create path', err
else
console.log 'created path', path, result
As @Egon mentioned above, there is no real folder management in BLOB storage.
You can achieve some features of a file system using '/' in the file name, but this has many limitations (for example, what happen if you need to rename a "folder"?).
As a general rule, I would keep my files as flat as possible in a container, and have my application manage whatever structure I want to expose to the end users (for example manage a nested folder structure in my database, have a record for each file, referencing the BLOB using container-name and file-name).
Got similar issue while trying Azure Sample first-serverless-app.
Here is the info of how i resolved by removing at front of $web.
Note: $web container was created automatically while enable static website.
Never seen $root container anywhere.
//getting Invalid URI error while following tutorial as-is
az storage blob upload-batch -s . -d $web --account-name firststgaccount01
//Remove "" @destination param
az storage blob upload-batch -s . -d $web --account-name firststgaccount01
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
how you filter or get all these files from "folder" ?
– afr0
Oct 16 '15 at 0:09