Create a Blob in Azure Storage

This tutorial guides you through the process of creating a blob in an Azure Storage account using the Azure portal and Azure CLI.

Prerequisites

  • An Azure account with an active subscription. If you don't have one, create a free account.
  • A Storage account in your Azure subscription. If you haven't created one, follow this guide.

Method 1: Using the Azure Portal

The Azure portal provides a user-friendly interface for managing your Azure resources, including creating blobs.

  1. Sign in to the Azure portal: portal.azure.com.
  2. Navigate to your Storage Account: In the search bar at the top, type "Storage accounts" and select it from the results. Then, select your desired storage account.
  3. Go to Containers: In the left-hand menu of your storage account, under "Data storage," select "Containers."
  4. Create a New Container: Click the "+ Container" button.
  5. Configure Container Settings:
    • Name: Enter a unique name for your container (e.g., my-blob-container). Container names must be lowercase letters and numbers.
    • Public access level: Choose the appropriate level. For this tutorial, "Private (no anonymous access)" is recommended.
  6. Click Create: Your new container will appear in the list.
  7. Navigate into the Container: Click on the name of the container you just created.
  8. Upload a Blob: Click the "Upload" button. You can drag and drop files or browse to select them. For now, we are creating an empty blob.
  9. Create Empty Blob: To create an empty blob, click on the "Upload" button, then select "Add folder" or "Upload blob". To simply create an empty blob, you can create a folder, or upload a file. If you upload a file, it will be created. For an empty blob, you can also use the Azure CLI or SDKs.
The Azure portal primarily facilitates uploading existing files as blobs. For creating truly empty blobs programmatically, use the Azure CLI or SDKs.

Method 2: Using Azure CLI

The Azure Command-Line Interface (CLI) allows you to manage Azure resources from your command line.

Make sure you have Azure CLI installed and configured. You can find instructions here.

Log in to Azure

If you haven't already, log in to your Azure account:

az login

Create a Container (if it doesn't exist)

You need a container to store your blobs. Replace <your-storage-account-name> and <your-container-name> with your actual values.

az storage container create --name <your-container-name> --account-name <your-storage-account-name> --auth-mode login

Or using an account key:

az storage container create --name <your-container-name> --account-name <your-storage-account-name> --account-key <your-account-key>

Create an Empty Blob

Use the az storage blob exists command to check if the blob already exists, and then az storage blob upload-chunk to create it. A more direct way for empty blobs is to upload an empty file or use the SDKs. For simplicity in this example, we'll demonstrate creating a blob from content, which implicitly creates it.

Let's create a simple text blob. First, create a local file with some content:

echo "This is the content of my first blob." > my-blob-content.txt

Now, upload this file as a blob:

az storage blob upload --account-name <your-storage-account-name> --container-name <your-container-name> --name <your-blob-name> --file my-blob-content.txt --auth-mode login

Replace <your-storage-account-name>, <your-container-name>, and <your-blob-name> (e.g., my-first-blob.txt) with your specific values.

To create a truly empty blob with Azure CLI without a local file, it's a bit more involved and often better handled by SDKs. However, you can effectively create an empty blob by uploading a zero-byte file:

# On Linux/macOS to create a zero-byte file
touch empty-blob.txt
# On Windows to create a zero-byte file
fsutil file createnew empty-blob.txt 0

az storage blob upload --account-name <your-storage-account-name> --container-name <your-container-name> --name empty-blob.txt --file empty-blob.txt --auth-mode login

This command will create a blob named empty-blob.txt within your specified container. You can then delete the local empty file if desired.

Next Steps

Now that you have created a blob, you can: