Upload a Blob to Azure Storage

This guide walks you through the process of uploading a blob to an Azure Storage account using various methods, including the Azure portal, Azure CLI, Azure PowerShell, and client libraries.

Prerequisites

Methods for Uploading Blobs

1. Using the Azure Portal

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

  1. Navigate to your storage account in the Azure portal.
  2. Under "Data storage", select "Containers".
  3. Click on the container where you want to upload the blob.
  4. Click the "Upload" button.
  5. Select the file(s) you want to upload. You can also specify options like blob type (block, page, append) and access tier.
  6. Click "Upload".

2. Using Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources from your terminal.

Upload a block blob

az storage blob upload \
    --account-name  \
    --container-name  \
    --name  \
    --file  \
    --auth-mode login

Replace placeholders with your actual values. For authentication, you can also use --account-key or --sas-token .

3. Using Azure PowerShell

Azure PowerShell provides a comprehensive set of cmdlets for managing Azure resources.

Upload a block blob

Set-AzStorageBlobContent `
    -Container  `
    -File  `
    -Blob  `
    -Context (New-AzStorageContext -StorageAccountName "" -StorageAccountKey "")

Ensure you have the Azure PowerShell module installed and are logged into your Azure account.

4. Using Client Libraries (Python Example)

Azure provides SDKs for various programming languages to interact with Azure Storage programmatically.

Upload a block blob using Python

from azure.storage.blob import BlobServiceClient

connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
container_name = "your-container-name"
local_file_path = "path/to/your/local/file.txt"
blob_name = "my-uploaded-blob.txt"

# Create the BlobServiceClient object
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# Get a client to interact with a specific blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)

print(f"Uploading blob to Azure Storage as blob '{blob_name}'...")

with open(local_file_path, "rb") as data:
    blob_client.upload_blob(data)

print("Upload complete.")

You can install the Python SDK with: pip install azure-storage-blob.

For other languages like C#, Java, Node.js, or Go, refer to the official Azure SDK documentation.

Blob Types

Azure Blob Storage supports three types of blobs:

When uploading using the Azure portal or CLI, the default is usually a block blob. You can specify the blob type when using client libraries or advanced CLI/PowerShell options.

Next Steps