Move Picture Files to Azure Blob for WordPress Blog

Please refer to the steps below on how do migrate Picture Files to Azure Blob for my WordPress Blog

  1. Login to Azure Portal and select the Subsscription that you want to work with
#Import the module into the PowerShell session
Import-Module AzureRM

#Connect to Azure with an interactive dialog for sign-in
$UserName = "kwyong@aventistech.com"
#"Azur3.t3st123@" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Users\kwyong\Box Sync\Scripts\kwyong.txt"
$Password = Get-Content "C:\Users\kwyong\Box Sync\Scripts\Cred-AventisTech.txt" | ConvertTo-SecureString

#Specify Credential with password 
$Credential = new-object -typename System.Management.Automation.PSCredential -ArgumentList $UserName,$Password

Connect-AzureRmAccount -Credential $Credential
#Switch to my MPN Account
Get-AzureRmSubscription | ? Name -eq "Microsoft Partner Network" | Select-AzureRmSubscription
  1. Provision a new Azure Storage Account
#Create a New Storage Account 
$RGroup = (Get-AzureRmResourceGroup | ? ResourceGroupName -eq "PRODUCTION").ResourceGroupName
$Location = "southeastasia"
$StroageAccountName = "prodavtstorage"
$skuName = "Standard_LRS"

#Create the storage account.
$storageAccount = New-AzureRmStorageAccount -ResourceGroupName $RGroup `
  -Name $StroageAccountName `
  -Location $location `
  -SkuName $skuName

#Retrieve the context. 
$ctx = $storageAccount.Context
  1. Provision a New Container for Bob Storage and try to upload file
#New Container for Bob Storage 
$containerName = "prodavtblobs"
New-AzureStorageContainer -Name $containerName -Context $ctx -Permission blob

#upload a file
Set-AzureStorageBlobContent -File "C:\Temp\Sample.jpg" `
  -Container $containerName `
  -Blob "sample.jpg" `
  -Context $ctx 
 ```

 4. List the file uploaded to Azure Blob 
 ```powershell
 #list 
Get-AzureStorageBlob -Container $containerName -Context $ctx

   Container Uri: https://prodavtstorage.blob.core.windows.net/prodavtblobs

Name                 BlobType  Length          ContentType                    LastModified         AccessTier SnapshotTime         IsDeleted 
----                 --------  ------          -----------                    ------------         ---------- ------------         --------- 
CDPVA-DiskSafe-01... BlockBlob 113564          image/jpeg                     2018-08-21 07:08:28Z                                 False     

  1. You can download Azure Storage Explorer which is a GUI Tool to upload image to Azure Blob

AzureBlob-01

You can upload multiple files at one time, and click Copy URL to obtain the URL link to link to your post.

  1. Verify that the image is linked to Azure Blob by using Google Chrome

AzureBlob-02

I noticed that the image is loaded instantly without any delay and quite impresive with the performane improved

Leave a Comment