1
votes

I want to create following folder structure on Azure:

mycontainer
   -images
       --2007
           ---img001.jpg
           ---img002.jpg

Now, one way is to use PUT Blob request and upload img001.jpg specifying the whole path as

PUT "mycontainer/images/2007/img001.jpg"

But, I want to first create the folders images and 2007 and then in a different request upload the blob img001.jpg.

Right now when I tried to doing this using PUT BLOB request:

StringToSign:

PUT











x-ms-blob-type:BlockBlob
x-ms-date:Tue, 07 Feb 2017 23:35:12 GMT
x-ms-version:2016-05-31
/account/mycontainer/images/

HTTP URL

sun.net.www.protocol.http.HttpURLConnection:http://account.blob.core.windows.net/mycontainer/images/

It is creating a folder but its not empty. By, default its creating an empty blob file without name.

Now, a lot of people say we can't create a empty folder. But, then how come, we can make it using the azure portal as the browser must be sending some type of rest request to create the folder.

I think it has to do something with Content-Type i.e. x-ms-blob-content-type, which should be specified in order to tell azure that its a folder not a blob. But, I am confused.

2

2 Answers

1
votes

This is not possible - the folder structure is virtual only.

See Get started with Azure Blob storage using .NET. You can only create a container, and everything else held in that container is a blob.

Excerpt:

As shown above, you can name blobs with path information in their names. This creates a virtual directory structure that you can organize and traverse as you would a traditional file system. Note that the directory structure is virtual only - the only resources available in Blob storage are containers and blobs.

1
votes

I want to first create the folders images and 2007 and then in a different request upload the blob img001.jpg

I agree with Brendan Green, currently, Azure blob storage just enable us to create virtual directory structure by naming blobs with path information in their names.

I think it has to do something with Content-Type i.e. x-ms-blob-content-type, which should be specified in order to tell azure that its a folder not a blob. But, I am confused.

You could check the description of Request Headers that could be set for Put Blob operation and you will find it does not support creating an empty folder by specifying some request headers.

Besides, as Gaurav Mantri said, if you really want to create an empty folder structure without content, you could try to use Azure File storage and it also enables us to use REST API to access Azure File storage. And the Create Directory operation cloud be used to create a new directory under the specified share or parent directory.

PUT https://myaccount.file.core.windows.net/myshare/myparentdirectorypath/mydirectory?restype=directory