Introduction to Azure Blob Storage
Azure Blob Storage is Microsoft's cloud object storage solution. Blob storage is optimized for storing massive amounts of unstructured data, such as text or binary data. Blobs can be used to serve images or documents directly to a browser, stored in parallel for fast I/O, or streamed while being written.
Key Concepts
- Storage Account: A container for all your Azure Storage data objects, including blobs, files, queues, and tables.
- Container: A logical grouping of blobs, similar to a directory in a file system.
- Blob: The fundamental unit of storage in Azure Blob Storage. There are three types of blobs: Block blobs, Append blobs, and Page blobs. For most use cases, Block blobs are the recommended choice.
Note: This quickstart focuses on using Block blobs, which are ideal for storing files, media, and backups.
Prerequisites
Before you begin, you'll need the following:
- An Azure subscription. If you don't have one, create a free account.
- An Azure Storage Account. You can create one in the Azure portal.
- The Azure CLI installed, or you can use Azure Cloud Shell.
Step 1: Create a Storage Account (if you don't have one)
You can create a storage account using the Azure portal, Azure CLI, or Azure PowerShell. Here's how to do it with the Azure CLI:
az storage account create \
--name mystorageaccountquickstart \
--resource-group myresourcegroup \
--location eastus \
--sku Standard_LRS
Replace mystorageaccountquickstart with a unique name for your storage account and myresourcegroup with your desired resource group name. The location should be a region near you.
1. Sign in to the Azure portal.
2. In the search bar, type "Storage accounts" and select it.
3. Click "Create".
4. Fill in the required fields: Subscription, Resource group, Storage account name (globally unique), Region, and Performance.
5. Click "Review + create" and then "Create".
Step 2: Create a Container
Containers are used to organize blobs. You can create a container using the Azure CLI:
az storage container create \
--name quickstartcontainer \
--account-name mystorageaccountquickstart \
--auth-mode login
Replace quickstartcontainer with your desired container name and mystorageaccountquickstart with your storage account name. Using --auth-mode login leverages your Azure AD credentials for authentication.
Step 3: Upload a Blob
Let's upload a simple text file named readme.txt to your container.
First, create a local file named readme.txt with some content:
Hello, Azure Blob Storage!
This is a quickstart example.
Now, upload the file using the Azure CLI:
az storage blob upload \
--account-name mystorageaccountquickstart \
--container-name quickstartcontainer \
--name readme.txt \
--file readme.txt \
--auth-mode login
Step 4: Download a Blob
You can download the blob you just uploaded. Let's download it to a new file named downloaded_readme.txt.
az storage blob download \
--account-name mystorageaccountquickstart \
--container-name quickstartcontainer \
--name readme.txt \
--file downloaded_readme.txt \
--auth-mode login
You can verify the content of downloaded_readme.txt to ensure it matches the original.
Step 5: List Blobs in a Container
To see the blobs in your container, you can use the following command:
az storage blob list \
--account-name mystorageaccountquickstart \
--container-name quickstartcontainer \
--auth-mode login \
--output table
Important: For production environments, consider using Managed Identities or Shared Access Signatures (SAS) for more secure authentication rather than logging in directly with your user credentials, especially for programmatic access.
Next Steps
Congratulations! You have successfully performed basic operations with Azure Blob Storage.
- Explore Azure Blob Storage features.
- Learn how to use access tiers to optimize costs.
- Discover how to use data transfer tools like AzCopy.
Ready to build?
Explore the developer guide for comprehensive information and code samples in various languages.