Quickstart: Create, download, and list blobs with Azure CLI

The Azure CLI is Azure's command-line experience for managing Azure resources. You can use it in your browser with Azure Deject Shell. You can too install it on macOS, Linux, or Windows and run it from the command line. In this quickstart, you lot learn to utilise the Azure CLI to upload and download information to and from Azure Blob storage.

Prerequisites

To access Azure Storage, you'll need an Azure subscription. If you don't already take a subscription, create a free account before you begin.

All access to Azure Storage takes place through a storage account. For this quickstart, create a storage account using the Azure portal, Azure PowerShell, or Azure CLI. For aid creating a storage account, see Create a storage business relationship.

Prepare your environment for the Azure CLI

  • Apply the Fustigate environment in Azure Cloud Beat out. For more than information, see Azure Cloud Shell Quickstart - Bash.

    Launch Cloud Shell in a new window

  • If you prefer to run CLI reference commands locally, install the Azure CLI. If you are running on Windows or macOS, consider running Azure CLI in a Docker container. For more data, see How to run the Azure CLI in a Docker container.

    • If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For additional sign-in options, encounter Sign in with the Azure CLI.

    • When you're prompted, install Azure CLI extensions on first use. For more information about extensions, see Apply extensions with the Azure CLI.

    • Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.

  • This commodity requires version 2.0.46 or later of the Azure CLI. If using Azure Cloud Trounce, the latest version is already installed.

Authorize access to Hulk storage

Yous can authorize access to Hulk storage from the Azure CLI either with Azure AD credentials or past using the storage business relationship access key. Using Azure Ad credentials is recommended. This article shows how to authorize Blob storage operations using Azure AD.

Azure CLI commands for data operations against Blob storage support the --auth-manner parameter, which enables y'all to specify how to authorize a given operation. Fix the --auth-mode parameter to login to authorize with Azure Ad credentials. For more information, run into Authorize access to blob or queue data with Azure CLI.

Only Hulk storage data operations support the --auth-style parameter. Direction operations, such as creating a resource group or storage account, automatically use Azure Advertising credentials for authorization.

To begin, sign-in to to your Azure account with the az login.

              az login \     --name <resources-group> \     --location <location>                          

Create a resource group

Create an Azure resource group with the az group create command. A resources group is a logical container into which Azure resource are deployed and managed.

Remember to supercede placeholder values in angle brackets with your own values:

              az group create \     --name <resource-grouping> \     --location <location>                          

Create a storage account

Create a general-purpose storage account with the az storage account create command. The general-purpose storage business relationship can be used for all four services: blobs, files, tables, and queues.

Call up to supplant placeholder values in angle brackets with your ain values:

              az storage account create \     --name <storage-account> \     --resource-group <resource-grouping> \     --location <location> \     --sku Standard_ZRS \     --encryption-services blob                          

Create a container

Blobs are always uploaded into a container. Y'all can organize groups of blobs in containers like to the way you organize your files on your computer in folders. Create a container for storing blobs with the az storage container create control.

The post-obit example uses your Azure AD account to authorize the operation to create the container. Before you create the container, assign the Storage Blob Data Contributor role to yourself. Fifty-fifty if you are the account possessor, you lot demand explicit permissions to perform data operations confronting the storage business relationship. For more information most assigning Azure roles, see Assign an Azure function for admission to blob data.

Remember to supplant placeholder values in angle brackets with your own values:

              az ad signed-in-user show --query objectId -o tsv | az role assignment create \     --part "Storage Blob Data Contributor" \     --assignee @- \     --scope "/subscriptions/<subscription>/resourceGroups/<resources-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>"  az storage container create \     --business relationship-name <storage-account> \     --proper name <container> \     --auth-style login                          

Important

Azure part assignments may accept a few minutes to propagate.

You can too use the storage account key to authorize the operation to create the container. For more information most authorizing data operations with Azure CLI, encounter Authorize access to hulk or queue data with Azure CLI.

Upload a blob

Blob storage supports block blobs, append blobs, and folio blobs. The examples in this quickstart show how to piece of work with cake blobs.

Outset, create a file to upload to a block hulk. If y'all're using Azure Cloud Vanquish, utilise the following command to create a file:

              vi helloworld                          

When the file opens, press insert. Type Howdy world, so press Esc. Next, type :x, then printing Enter.

In this case, y'all upload a hulk to the container you lot created in the last step using the az storage blob upload command. It's not necessary to specify a file path since the file was created at the root directory. Retrieve to supervene upon placeholder values in angle brackets with your ain values:

              az storage blob upload \     --account-name <storage-account> \     --container-name <container> \     --name helloworld \     --file helloworld \     --auth-manner login                          

This operation creates the blob if it doesn't already exist, and overwrites information technology if information technology does. Upload as many files as yous similar earlier continuing.

To upload multiple files at the same fourth dimension, you can use the az storage hulk upload-batch control.

List the blobs in a container

List the blobs in the container with the az storage hulk list command. Remember to replace placeholder values in angle brackets with your own values:

              az storage blob list \     --account-name <storage-business relationship> \     --container-name <container> \     --output table \     --auth-fashion login                          

Download a blob

Utilise the az storage blob download control to download the blob you uploaded earlier. Remember to replace placeholder values in angle brackets with your own values:

              az storage hulk download \     --account-proper noun <storage-account> \     --container-name <container> \     --name helloworld \     --file ~/destination/path/for/file \     --auth-mode login                          

Data transfer with AzCopy

The AzCopy command-line utility offers high-functioning, scriptable data transfer for Azure Storage. You lot can utilize AzCopy to transfer data to and from Blob storage and Azure Files. For more information about AzCopy v10, the latest version of AzCopy, see Get started with AzCopy. To learn most using AzCopy v10 with Blob storage, see Transfer information with AzCopy and Hulk storage.

The following example uses AzCopy to upload a local file to a blob. Remember to replace the sample values with your own values:

              azcopy login azcopy re-create 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myTextFile.txt'                          

Clean upwardly resource

If you want to delete the resources y'all created equally part of this quickstart, including the storage account, delete the resource grouping past using the az group delete command. Remember to supplant placeholder values in angle brackets with your ain values:

              az group delete \     --name <resources-group> \     --no-look                          

Side by side steps

In this quickstart, you learned how to transfer files between a local file system and a container in Azure Hulk storage. To learn more than about working with Hulk storage by using Azure CLI, select an choice below.