Azure Blob Storage in Azure is a scalable, secure, and cost-effective way to store unstructured data such as documents, images, and backups. Efficiently managing data in Azure Blob Storage is crucial for modern cloud applications and services. One of the most efficient tools to transfer data to and from Azure Blob Storage is AzCopy — a command-line utility provided by Microsoft.
In this article, we’ll walk through how to upload files from your local machine to Azure Blob Storage using AzCopy.
Prerequisites
- You have an Azure Storage Account.
- You have either:
- Azure CLI installed, or
- A valid Shared Access Signature (SAS) token or Azure AD credentials.
- You have AzCopy installed.
File Uploading To Azure Blob Storage using AzCopy
Getting Started
AzCopy also known as Azure AzCopy is a command-line tool provided by Microsoft for efficiently copying data to and from Azure Storage services. It's particularly useful when working with large amounts of data or automating data transfer tasks. It works with:
- Azure Blob Storage
- Azure Files
- Azure Data Lake Storage (Gen2)
It’s especially useful for automating data transfer processes or handling large-scale file uploads and downloads.
Download AzCopy
- Visit: https://aka.ms/downloadazcopy
- Download the version for your OS (Windows, Linux, macOS)
Install AzCopy (v10+)
- Extract the downloaded Package
- Move azcopy.exe to a permanent folder (e.g., C:\AzCopy).
- Add that folder to your System Environment Variables > Path.
- The next step is to veryfi the instalation
- Open command prompt and execute below command
azcopy
- You will get the installed azure AzCopy version with default command information
- Open command prompt and execute below command
Authenticate with Azure
To interact with Azure Blob Storage, you need to authenticate first. There are two ways to authenticate, as outlined below.
Azure AD (Interactive Login)
azcopy login
This opens a browser for you to log in using your Azure credentials. Alternatively, if you're using a shared access signature (SAS) URL, no login is needed, append a SAS token to each source or destination URL that use in your AzCopy commands like below.
azcopy copy "https://<storageaccount>.blob.core.windows.net/<container>/<file>?<SAS-token>" <local-file-path>
Create a container
The azcopy make
command creats container in Azure blog storage.
azcopy make 'https://<storageaccount>.blob.core.windows.net/mycontainer'
Example
azcopy make 'https://kailashsblogs.blob.core.windows.net/mycontainer'
Syntax : Using SAS Token
azcopy make 'https://<storageaccount>.blob.core.windows.net/mycontainer?<SAS-token>
Upload a Folder:
Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>' --recursive
Example
azcopy copy 'C:\myDirectory' 'https://kailashsblogs.blob.core.windows.net/mycontainer/myBlobDirectory' --recursive
Syntax : Using SAS Token
azcopy copy "/local/path/folder" "https://<storageaccount>.blob.core.windows.net/<container>?<SAS-token>" --recursive=true
Upload Folder Contents:
Files from a folder can be uploaded without copying the containing folder itself by using the Azure AzCopy command. use the wildcard symbol (*) to upload the folder contents.
Syntax azcopy copy '<local-directory-path>\*' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<directory-path>'
Example
azcopy copy 'C:\myDirectory\*' 'https://kailashsblogs.blob.core.windows.net/mycontainer/myBlobDirectory'
Upload a File to Blob Storage:
The following AzCopy command uploads a file from the local computer to Azure Blob Storage.
azcopy copy "/local/path/file.txt" "https://<storageaccount>.blob.core.windows.net/<container>?<SAS-token>" --recursive=false
Upload Specific Files:
Use the following AzCopy command to upload specified files from your local computer to blob Storage.
azcopy copy 'C:\myDirectory\*' 'https://<storageaccount>.blob.core.windows.net/mycontainer/myContainer' --include-path 'myFile.txt;myFile1.txt;myFile2.txt'
With the AzCopy command, the --include-pattern option allows you to upload specific files, with file names separated by semicolons (;).
Upload Specific File and Folder:
azcopy copy 'C:\myDirectory\*' 'https://<storageaccount>.blob.core.windows.net/mycontainer/myContainer' --include-path 'images;myFile2.txt' --recursive'
In this above example, AzCopy transfers the C:\images directory and the C:\myDirectory\myFile.txt file. Include the --recursive option to transfer all files in the C:\images directory.
Summary
AzCopy is a powerful and flexible tool for uploading data to Azure Blob Storage. Whether you are uploading a single file, an entire folder, or selected files based on patterns, AzCopy provides an efficient and scriptable solution. I hope you found this information helpful.
Thanks