Azure Storage Documentation

Quickstart: Upload a blob to Azure Storage

This quickstart guide walks you through the process of uploading a blob to Azure Blob Storage using the Azure CLI.

Prerequisites:

  • An Azure account with an active subscription. If you don't have one, create a free account.
  • Azure CLI installed. If you haven't installed it, follow the installation guide.

1. Sign in to your Azure account

Open your terminal or command prompt and sign in to Azure:

az login

This command opens a browser window for you to authenticate your account.

2. Create a resource group

A resource group is a logical container for Azure resources. Create a new resource group with the following command:

az group create --name MyResourceGroup --location eastus

Replace MyResourceGroup and eastus with your desired name and location.

3. Create a storage account

Create a general-purpose v2 storage account. This command creates the storage account and returns a JSON object containing information about the account.

az storage account create --resource-group MyResourceGroup --name mystorageaccountname --sku Standard_LRS --kind StorageV2

Replace MyResourceGroup with the name of your resource group and mystorageaccountname with a globally unique name for your storage account.

4. Get the storage account connection string

You'll need the connection string to authenticate your application to your storage account. Retrieve it using the following command:

az storage account show-connection-string --resource-group MyResourceGroup --name mystorageaccountname --output tsv

Copy the connection string and store it securely. For local development, you can set it as an environment variable.

5. Upload a blob

Now, let's upload a sample file to the blob container. First, create a simple text file named sample.txt with some content.

Hello, Azure Blob Storage!

Next, use the az storage blob upload command to upload the file:

az storage blob upload --account-name mystorageaccountname --container-name mycontainer --name sample.txt --file sample.txt --connection-string YOUR_CONNECTION_STRING

This command uploads the sample.txt file to a container named mycontainer in your storage account.

6. Verify the upload

You can verify the upload by listing the blobs in the container:

az storage blob list --account-name mystorageaccountname --container-name mycontainer --connection-string YOUR_CONNECTION_STRING --output table

You should see sample.txt listed in the output.

Next Steps

Congratulations! You've successfully uploaded a blob to Azure Blob Storage. Here are some resources to help you continue your learning: