Intro

In the previous post I have covered Stored Access Policies for Azure Table Service, in this post I am going to cover basic PowerShell commands related to Azure Blob Service.

Prerequisites

Refer to previous posts to get started with Azure Storage Services.

Code

Azure Blob storage is a service for storing large amounts of unstructured object data, such as text or binary data, that can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob storage to expose data publicly to the world, or to store application data privately. There are couple of useful PowerShell commands that every developer needs to know to successfully work with Azure Blob Service.

Every blob must be in a container, so lets create a new container first:

New-AzureStorageContainer -Name "container-1" -Permission Blob

CloudBlobContainer : Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
Permission         : Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
PublicAccess       : Blob
LastModified       : 10/25/2016 4:04:34 AM +00:00
ContinuationToken  :
Context            : Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext
Name               : container-1

This code creates container that can be accessed by anonymous users.

To get a full list of containers run the following command:

Get-AzureStorageContainer

CloudBlobContainer : Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
Permission         : Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
PublicAccess       : Blob
LastModified       : 10/25/2016 4:04:34 AM +00:00
ContinuationToken  :
Context            : Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext
Name               : container-1

To upload a file from local environment to the container run the following command:

Set-AzureStorageBlobContent -File "1.txt" -Container "container-1"

ICloudBlob        : Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
BlobType          : BlockBlob
Length            : 5154
ContentType       : application/octet-stream
LastModified      : 10/25/2016 4:08:03 AM +00:00
SnapshotTime      :
ContinuationToken :
Context           : Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext
Name              : 1.txt

This command uploads file 1.txt to the container container-1. Now it is possible to get the URI of the file:

(Get-AzureStorageBlob  -Container "container-1" -Blob "1.txt").ICloudBlob.Uri.AbsoluteUri
https://default748347.blob.core.windows.net/container-1/1.txt

It is possible to download this file using this URL.

Lets remove the blob and the container:

Remove-AzureStorageBlob -Container "container-1" -Blob "1.txt"
Remove-AzureStorageContainer -Container "container-1"

Summary

In this post I showed how to create a new container and copy a file from local environment into cloud, I also showed that it is possible to get a URL of newly uploaded file. In the next post I am going to show how to interact with Azure Blob Service from simple console application.


;