How To Upload Files to Microsoft Azure

Posted on June 9, 2015 by Aidan Finn in Microsoft Azure with 0 Comments

In this post I will show you how to upload files to an Azure storage account. This can be useful if you want to perform an offline upload of virtual hard disks, tools, or scripts.

Prepare the Storage Account

A file must be uploaded into a container in a storage account. Containers are like folders; a logical mechanism for organizing files in Azure. In my example, I want to upload a PowerShell script to Azure, so I will create a container called scripts. You can do this in two ways, the GUI or PowerShell.

In the management portal, browse into your storage account, click Containers, and click Add. Name the container, set the access level and close the wizard. Note that the name must be in lowercase.

Create a new Azure storage account container (Image credit: Aidan Finn)

Create a new Azure storage account container (Image Credit: Aidan Finn)

In case you are curious, the access option controls if and how the public can access the contents of your container:

Control access to an Azure storage account container (Image Credit: Aidan Finn)

Control access to an Azure storage account container (Image Credit: Aidan Finn)

Alternatively, you can create a new container using PowerShell. Note that before we go anywhere, we must set a default storage account for use with PowerShell. This is a little annoying; you cannot specify a storage account in each storage cmdlet. Instead you have to change the default storage account each time.

Sponsored

The syntax for setting a default storage account is:

In my example, I am working with a storage account called petridemo in a subscription called Azure in Open:

Now I can use New-AzureStorageContainer to create the new container to store my future upload:

Upload the File

Microsoft offers you PowerShell as the solution for uploading files to an Azure storage account. There are some third-party solutions that offer a UI, but for the purposes of this article, we’ll stick with Microsoft’s method, which is based on a cmdlet called Set-AzureStorageBlobContent:

In my example, I am going to upload C:\Temp\ServerCore.ps1 to my new scripts container in the petridemo storage account.

Sponsored

I have already set my default storage account using Set-AzureSubscription. Now I can run Set-AzureStorageBlobContent:

A progress bar appears in the PowerShell console to indicate upload progress. One the job is done, you can browse into your storage account container to verify that the upload is completed.

Verifying that the file was uploaded to the Azure Storage Account [Image Credit: Aidan Finn]

Verifying that the file was uploaded to the Azure Storage Account [Image Credit: Aidan Finn]

Sponsored

Tagged with , , , ,