How to Create a Sub Directory in a Blob Container in Microsoft Azure


Storing files in a container is essential for production applications that need to persist data. But storing large files or images in a database is not ideal.

Luckily, Azure Blob storage offers an easy way to store large files in the cloud.

This article will show you how to create a subdirectory in a blob container in Microsoft Azure.

What is Azure Blob storage?

azure blob storage

Azure Blob storage account is one of the many Microsoft Azure services. It allows customers to store massive volumes of unstructured data on Microsoft’s data storage infrastructure.

The term blob stands for Binary Large Object, which contains items such as photos and multimedia files. These are referred to as unstructured data since they do not adhere to any particular data model.

Blob storage is a convenient way of storing large amounts of data, especially if you have many large image or video files. Blob storage is available as part of Microsoft’s Azure service, meaning that you don’t need to own any hardware to use it. In addition, it’s only required to create an Azure Storage Account from which you can access your blob storage. 

Blob storage, for example, would include preserving backups of prior versions of a site, as well as its content and pictures, which would need to be available from several places. When a corporation uses Azure data storage, it may make this content more accessible and faster to access than if it was maintained on a single-location server.

With Azure Blob storage, files (pictures, movies, training documents, and so on) are placed in containers that behave similarly to directories. The storage account is then linked to these. When constructing an address to grant access to a file in Azure data storage, it will simply link the storage account and the blob’s location.

Azure Blob Storage: How to create a subfolder?

All blobs must be contained within a blob container, which is just a logical collection of blobs. An account may have an infinite number of containers, each of which can hold an infinite number of blobs.

When it comes to Azure Blob Storage, there is only one layer of virtual folders. So you may simulate creating subfolders and the file system, but everything will be in one layer, the container itself.

However, you can have blob names that contain a ‘/’ for generating a virtual “file-system” type storage so that you can do whatever you want with the way you store. Also, you may search for a blob at the virtual level by providing a partial string up to a ‘/’.

The combination of appending a ‘/’ to a route and a partial text for search results in the creation of a virtual “file-system” storage.

How do I make a subfolder in Azure Blob Storage in Azure Portal?

We’ll look at how to make an Azure blob container. Follow the steps below to build an Azure storage container using the Azure Portal.

Step 1: In the Azure interface, navigate to the storage account you created earlier.

Step 2: From the storage account’s left menu, pick Containers from the Blob service area.

Step 3: Select the + Container option.

Step 4: Give your new container a name.

Choose a degree of access for the public. Choosing the default setting Private (no anonymous access) is preferable. You can also alter it based on your company’s needs.

Step 5: To build the container, click the Create the container button.

You will see the notification “Successfully created storage container”.

You may find the newly formed container on the Storage account | Containers page. This is how you may use the Azure interface to build the container. So now you have a storage account and a container. Now is the time to upload the blob.

To create a subfolder in this new blob container, follow the following steps:

  • Click the Upload button in the container.
  • Select the file you want to upload.
  • Under the Upload to folder option, type the “folder/subfolder”, or for example “assets/js”.
  • Click the Upload button.

The new file will be located under the folder/subfolder hierarchy (assets/js in the above example).

How do I make a subfolder in Azure Blob Storage? In Microsoft Azure Storage Explorer

Azure Storage Explorer is a free tool from Microsoft that allows you to visualize your cloud-enabled data. It can help you quickly browse, manage, and search through your data.

To make a subfolder inside the Azure Storage, follow the following instructions:

  1. Open the Azure Storage Explorer. Make sure to connect it to your Azure subscription.
  2. Open the existing blob container.
  3. Click on the New Folder icon.
  4. The modal window will appear with the following message: “This will create a virtual folder. A virtual folder does not actually exist in Azure until you paste, drag or upload blobs into it. To paste a blob into a virtual folder, copy the blob before creating the folder.
  1. Type in the folder and subfolder hierarchy, separating them with a slash “/” sign.
  2. Upload the file to the newly created subfolder.

The file should appear in the subfolder.

How do I make a subfolder in Azure Blob Storage using the code?

The final approach is to use the C# code to create the subfolder while uploading the blob to the Blob container.

string filename = "top/subfolder/someimage.jpg";
var cloudStorageAccount = CloudStorageAccount.Parse(ConnectionString);
var blob = cloudBlobContainer.GetBlockBlobReference(filename);
blob.StreamWriteSizeInBytes = 20 * 1024;
blob.UploadFromStream(imageStream);

Can Azure Blob storage store structured data?

You cannot store structured data in Azure. Blob storage is a part of the Azure Storage Account service and is designed to hold large volumes of unstructured data. Unstructured data is information that does not conform to a certain data model or description, such as text or binary data.

Microsoft Azure Blob Storage enables you to redefine your storage in a dispersed environment where moving huge amounts of unstructured data might tax your organization’s data management resources.

It provides data integrity and access to data anytime and from any location. Azure Blob Storage enables businesses to better organize their data assets and make them available to multiple departments and nations based on their needs. Various data management and cloud data protection solutions are available to assist organizations in doing so securely and effectively.

When combined with other storage techniques, Microsoft Azure Blob Storage can be the missing link that makes cloud storage even more efficient than on-premise storage while still providing all of the flexibility cloud computing is known for.

Conclusion

One of the major benefits for organizations is that Azure Blob storage allows them to centralize all of their content assets. In addition, the speed, scalability, simplicity of access, and security (from both accidents and thieves) of such cloud storage make it particularly appealing to all mid-sized and big enterprises.

Recent Posts