How Quickly Upload Files from URL to Azure Blob Storage Using Azure CLI in 2 steps

GuruPrakash July 27, 2024
how-quickly-upload-files-from-url-to-azure-blob-storage-using-azure-cli-in-2-steps

The Azure CLI's az storage blob upload command lets you upload local files to Azure Blob Storage. However, sometimes it’s more convenient to upload a file directly from an HTTP(S) URL to Azure Blob Storage. Unfortunately, the Azure CLI doesn’t support this directly—you need to download the file locally first. This article explores using Bash and PowerShell commands to download a file from a URL and then upload it to Azure Blob Storage. Plus, if you use these commands in the Azure Cloud Shell, you won’t have to worry about your local network’s bandwidth speeds or limits, which is great for uploading large files.

How to Upload Files from a URL to Azure Blob Storage?

Let's start by looking at how to upload a file to Azure Blob Storage using the Azure CLI. In this scenario, we have a file hosted online, accessible via an HTTP(S) URL. Our goal is to take this URL and upload the file to Azure Blob Storage.

1. Download the File(s)

Before uploading the file to Azure Blob Storage, we need to download it. You can do this using `wget` or `curl` in bash, or Invoke-WebRequest in PowerShell.

Invoke-WebRequest -Uri "https://example.com/documents/files.zip" -OutFile "docfiles.zip"	

2. Uploading the File to Azure Blob Storage

With the file downloaded, we can now upload it to Azure Blob Storage using the Azure CLI's az storage blob upload command.

az storage blob upload --account-name  \
  --account-key  \
  --container-name  \
  --name  \
  --file "docfiles.zip"	

Make sure to set the command arguments correctly for your Azure Blob Storage account:

  • --account-name – name of your Azure Storage account
  • --account-key – key for your Azure Storage account, used for authentication
  • --container-name – name of the container within your Azure Storage account where the blob will be uploaded
  • --name – name you want to give the blob, which can be different from the local file name
  • --file – path and name of the local file you want to upload to blob storage.

2.1 Delete the File

After uploading the downloaded file to Azure Blob Storage, you can delete the local copy from your machine (or from Azure Cloud Shell if you used it).

Remove-Item -Path "docfiles.zip"	
- or -
BASH:
rm "docfiles.zip"

3. Bash/Powershell scripts to automate file upload from HTTP(S) URL to Azure Blob Storage

Conclusion

In this article, we explored how to upload a file with a known HTTP(S) URL to an Azure Blob Storage container. Although the Azure CLI can’t directly upload from a URL, you can first download the file locally and then use the CLI to upload it to Azure Blob Storage. Additionally, running these commands in Azure Cloud Shell saves your local network bandwidth.

also view other related posts,