Upload and Download Azure Blob Storage using AZCopy
AZCopy is a command-line utility for uploading and downloading Azure Blob Storage files.
At the time of writing, the most recent version of AZCopy is V10. So, you can get the AZCopy executable file from the link below.
https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10If the link does not work, look for the most recent version of AZCopy and download the executable file. Download the file and save it in a location that is convenient for you on your computer.
In this blog, I'll show you how to use an SAS token to upload and download files from Azure Blob Storage.
Get SAS token
First, let's look at how to obtain an SAS token.
- Go to the Azure Storage Account to which you want to upload or download files.
- On the right side, under Security + networking, choose Shared access signature.
- Locate the Allowed resource types and choose the preferred resource type. I'm going with all three options (Service, Container, Object)
- Enter the start and expiry date and times. That is when the authorization will begin to work and when it will expire. You can only access the resource for two days if it is two days.
- Select the Generate SAS and connection string option.
- Make a copy of the SAS token
Download a Specific File
To obtain a file for download. Launch a command prompt and then relocate the AZCopy folder (which you downloaded). The syntax for downloading a file is as follows.
- [account] - Name of the storage account
- [container]/[path-to-blob] - path and container name
- [SAS token] - Which you generated and copied from the Azure site.
- [path-to-file] - Path to download a file in local machine
A sample command prompt script is provided below.
The output of the above command prompt script is shown below.
Upload a Specific File
The upload procedure is similar to the download procedure. Only the order will be altered. Always put the source file name first.
A command prompt sample script is provided below.
Download all of the files in the specified container
Let's look at how to download the specific container files to your local machine next. The syntax for downloading all containers from a specific file is as follows.
A command prompt script for downloading entire container files is provided below. To copy the folder structure, the –recursive attribute was added.
Upload all of the files in the specified folder to Azure blob storage container
The syntax below is for uploading all folder files to an Azure blob storage container.
The following is an example command prompt script that will upload all of the files in a specific folder to an Azure blob storage container.
Copy from one Azure Blob Storage to another Azure Blob Storage
You can directly copy one container file to another container. The syntax for that is as follows:
I hope this helps you. Keep coding.
Comments
Post a Comment