Getting Started with Azure Blob Storage
Welcome to Azure Blob Storage, Microsoft's highly scalable and secure object storage solution for the cloud. This guide will walk you through the essential steps to get you up and running with Blob Storage.
What is Azure Blob Storage?
Azure Blob Storage is designed for storing massive amounts of unstructured data, such as text or binary data. It's optimized for scenarios that involve directly serving images or documents to a web browser, storing files for distributed access, streaming video and audio, storing data for backup and restore, disaster recovery, and archiving. Blob storage is a RESTful service that can be accessed from anywhere in the world via HTTP or HTTPS.
Key Concepts
- Storage Account: A unique namespace in Azure for your storage data. All Azure Storage objects are stored within a storage account.
- Containers: Similar to a file system, a container is a grouping of blobs. A storage account can contain an unlimited number of containers.
- Blobs: Objects that can store large amounts of unstructured data, such as text or binary data. There are three types of blobs: Block Blobs, Append Blobs, and Page Blobs.
Prerequisites
Before you begin, you'll need:
- An Azure account. If you don't have one, you can create a free account.
- The Azure CLI installed (optional, but recommended for command-line management).
Step 1: Create an Azure Storage Account
You can create a storage account using the Azure portal, Azure CLI, or Azure PowerShell.
Using the Azure Portal:
- Sign in to the Azure portal.
- Click on Create a resource.
- Search for "Storage account" and select it.
- Click Create.
- Fill in the required fields: Subscription, Resource group, Storage account name (globally unique), Region, and Performance tier.
- Review and create the storage account.
Using the Azure CLI:
Open your terminal or command prompt and run the following commands:
# Log in to your Azure account
az login
# Set your subscription (replace )
az account set --subscription <your-subscription-id>
# Create a resource group (if you don't have one)
az group create --name myResourceGroup --location eastus
# Create a storage account
az storage account create \
--name mystorageaccount <--replace-with-globally-unique-name> \
--resource-group myResourceGroup \
--location eastus \
--sku Standard_LRS
Remember to replace mystorageaccount<--replace-with-globally-unique-name>
with a globally unique name for your storage account.
Step 2: Create a Container
Containers organize your blobs. They are case-insensitive and must start with a letter or number.
Using the Azure Portal:
- Navigate to your storage account in the Azure portal.
- Under Data storage, click on Containers.
- Click + Container.
- Enter a name for your container (e.g.,
mycontainer
) and set the public access level. - Click Create.
Using the Azure CLI:
# Create a container (replace with your storage account name and desired container name)
az storage container create \
--name mycontainer \
--account-name mystorageaccount <--replace-with-your-storage-account-name> \
--auth-mode login
Step 3: Upload a Blob
You can upload various types of files as blobs.
Using the Azure Portal:
- Navigate to your storage account and then to the container you created.
- Click Upload.
- Select the file you wish to upload.
Using the Azure CLI:
This example uploads a local file named example.txt
to your container.
# Upload a blob (replace with your storage account name, container name, and local file path)
az storage blob upload \
--account-name mystorageaccount <--replace-with-your-storage-account-name> \
--container-name mycontainer \
--name example.txt \
--file /path/to/your/local/example.txt \
--auth-mode login
You can upload multiple files or create directories within a container using the CLI or SDKs.
Step 4: Accessing Your Blob
Once uploaded, you can access your blob. The access method depends on the container's public access level.
- Private: Access is restricted to authenticated users or applications. You'll typically use shared access signatures (SAS) or Azure AD authentication.
- Blob: Blobs are publicly accessible anonymously, but containers are not.
- Container: All blobs in the container are publicly accessible anonymously.
If your container's access level is set to Blob
or Container
, you can access the blob directly via its URL:
https://<storage-account-name>.blob.core.windows.net/<container-name>/<blob-name>
Next Steps
Congratulations! You've successfully created a storage account, a container, and uploaded a blob.
- Explore the Blob Storage documentation for advanced features like different blob types, lifecycle management, and security.
- Learn how to use the Azure Storage SDKs to integrate Blob Storage into your applications.
- Discover how to manage access with Shared Access Signatures (SAS).