Edit

Share via


Upload files to Azure Blob storage by using AzCopy

You can upload files and directories to Blob storage by using the AzCopy v10 command-line utility.

To see examples for other types of tasks such as downloading blobs, synchronizing with Blob storage, or copying blobs between accounts, see the links presented in the Next Steps section of this article.

Get started

See the Get started with AzCopy article to download AzCopy and learn about the ways that you can provide authorization credentials to the storage service.

Note

The examples in this article assume that you provide authorization credentials by using Microsoft Entra ID.

If you want to use a SAS token to authorize access to blob data, append that token to the resource URL in each AzCopy command. For example: 'https://<storage-account-name>.blob.core.windows.net/<container-name><SAS-token>'.

Create a container

Use the azcopy make command to create a container.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you use a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

Syntax

azcopy make 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>'

Example

azcopy make 'https://mystorageaccount.blob.core.windows.net/mycontainer'

Example (Data Lake Storage endpoint)

azcopy make 'https://mystorageaccount.dfs.core.windows.net/mycontainer'

For detailed reference docs, see azcopy make.

Upload a file

Upload a file by using the azcopy copy command.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you use a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

Syntax

azcopy copy '<local-file-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<blob-name>'

Example

azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myTextFile.txt'

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.dfs.core.windows.net/mycontainer/myTextFile.txt'

You can also upload a file by using a wildcard symbol (*) anywhere in the file path or file name. For example: 'C:\myDirectory\*.txt', or C:\my*\*.txt.

Upload a directory

Upload a directory by using the azcopy copy command.

This example copies a directory (and all of the files in that directory) to a blob container. The result is a directory in the container with the same name.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you use a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

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://mystorageaccount.blob.core.windows.net/mycontainer' --recursive

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.windows.net/mycontainer' --recursive

To copy to a directory within the container, just specify the name of that directory in your command string.

Example

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myBlobDirectory' --recursive

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.windows.net/mycontainer/myBlobDirectory' --recursive

If you specify the name of a directory that doesn't exist in the container, AzCopy creates a new directory with that name.

Upload directory contents

Upload the contents of a directory by using the azcopy copy command. Use the wildcard symbol (*) to upload the contents without copying the containing directory itself.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you use a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

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://mystorageaccount.blob.core.windows.net/mycontainer/myBlobDirectory'

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.dfs.core.windows.net/mycontainer/myBlobDirectory'

Append the --recursive flag to upload files in all subdirectories.

Upload specific files

You can upload specific files by using complete file names, partial names with wildcard characters (*), or by using dates and times.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

Specify multiple complete file names

Use the azcopy copy command with the --include-path option. Separate individual file names by using a semicolon (;).

Syntax

azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>' --include-path <semicolon-separated-file-list>

Example

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer' --include-path 'photos;documents\myFile.txt' --recursive'

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.windows.net/mycontainer' --include-path 'photos;documents\myFile.txt' --recursive'

In this example, AzCopy transfers the C:\myDirectory\photos directory and the C:\myDirectory\documents\myFile.txt file. Include the --recursive option to transfer all files in the C:\myDirectory\photos directory.

You can also exclude files by using the --exclude-path option. To learn more, see azcopy copy reference docs.

Use wildcard characters

Use the azcopy copy command with the --include-pattern option. Specify partial names that include the wildcard characters. Separate names by using a semicolon (;).

Syntax

azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>' --include-pattern <semicolon-separated-file-list-with-wildcard-characters>

Example

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer' --include-pattern 'myFile*.txt;*.pdf*'

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.windows.net/mycontainer' --include-pattern 'myFile*.txt;*.pdf*'

You can also exclude files by using the --exclude-pattern option. To learn more, see azcopy copy reference docs.

The --include-pattern and --exclude-pattern options apply only to filenames and not to the path. If you want to copy all of the text files that exist in a directory tree, use the -recursive option to get the entire directory tree, and then use the -include-pattern and specify *.txt to get all of the text files.

Upload files that were modified before or after a date and time

Use the azcopy copy command with the --include-before or --include-after option. Specify a date and time in ISO-8601 format (for example: 2020-08-19T15:04:00Z).

The following examples upload files that were modified on or after the specified date.

Syntax

azcopy copy '<local-directory-path>\*' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-or-directory-name>' --include-after <Date-Time-in-ISO-8601-format>

Example

azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.blob.core.windows.net/mycontainer/FileDirectory'  --include-after '2020-08-19T15:04:00Z'

Example (Data Lake Storage endpoint)

azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.dfs.core.windows.net/mycontainer/FileDirectory'   --include-after '2020-08-19T15:04:00Z'

For detailed reference, see the azcopy copy reference docs.

Upload with index tags

You can upload a file and add blob index tags to the target blob.

If you use Microsoft Entra authorization, assign the Storage Blob Data Owner role to your security principal, or give it permission to the Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/write Azure resource provider operation through a custom Azure role. If you use a Shared Access Signature (SAS) token, the token must provide access to the blob's tags through the t SAS permission.

To add tags, use the --blob-tags option with a URL encoded key-value pair. For example, to add the key my tag and the value my tag value, include --blob-tags='my%20tag=my%20tag%20value' in the destination parameter.

Separate multiple index tags with an ampersand (&). For example, to add the key my second tag and the value my second tag value, the complete option string is --blob-tags='my%20tag=my%20tag%20value&my%20second%20tag=my%20second%20tag%20value'.

The following examples show how to use the --blob-tags option.

Tip

These examples enclose path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you use a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

Upload a file

azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myTextFile.txt' --blob-tags='my%20tag=my%20tag%20value&my%20second%20tag=my%20second%20tag%20value'

Upload a directory

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer' --recursive --blob-tags='my%20tag=my%20tag%20value&my%20second%20tag=my%20second%20tag%20value'

Upload directory contents

azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myBlobDirectory' --blob-tags='my%20tag=my%20tag%20value&my%20second%20tag=my%20second%20tag%20value'

Note

If you specify a directory for the source, all the blobs that you copy to the destination have the same tags that you specify in the command.

Upload with optional flags

You can tweak your upload operation by using optional flags. Here's a few examples.

Scenario Flag
Upload files as Append Blobs or Page Blobs. --blob-type=[BlockBlob|PageBlob|AppendBlob]
Upload to a specific access tier (such as the archive tier). --block-blob-tier=[None|Hot|Cool|Archive]

For a complete list, see options.

Specify source and destination types

AzCopy uses the --from-to parameter to explicitly define the source and destination resource types when automatic detection might fail - such as in piping scenarios or emulators. This parameter helps AzCopy understand the context of the transfer and optimize accordingly.

FromTo Value Description
LocalBlob Upload from local file system to Azure Blob Storage
LocalBlobFS Upload from local file system to Azure Data Lake Gen2 (BlobFS)
PipeBlob Stream data from a pipe to Azure Blob Storage
PipeFile Stream data from a pipe to Azure File Storage

Next steps

Find more examples in these articles:

See these articles to configure settings, optimize performance, and troubleshoot issues: