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. Prepare the password file by using Master Key – You can just copy the Script Folder and run it on any other machines with AzureRM installed
$KeyFile = "C:\Users\kwyong\Box Sync\Scripts\MasterKey.key"
$PasswordFile = "C:\Users\kwyong\Box Sync\Scripts\AzureMPN.txt"

$Key = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | out-file $KeyFile

(get-credential).Password | ConvertFrom-SecureString -key (get-content $KeyFile) | set-content $PasswordFile
  1. Login to Azure Portal and select the Subsscription that you want to work with
#Install AzureRM if you had not installed previously 
Install-Module -Name AzureRM -AllowClobber

#Import the module into the PowerShell session
Import-Module AzureRM

$Username = "[email protected]"
$KeyFile = "C:\Users\kwyong\Box Sync\Scripts\MasterKey.key"
$PasswordFile = "C:\Users\kwyong\Box Sync\Scripts\AzureMPN.txt"
$Password = Get-Content $PasswordFile | ConvertTo-SecureString -Key (Get-Content $KeyFile) 

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

Connect-AzureRmAccount -Credential $Credential
  1. Switch to my Microsoft MPN Account
#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 

  1. List the file uploaded to Azure Blob

Get-AzureStorageBlob -Container $containerName -Context $ctx Container Uri: https://prodavtstorage.blob.core.windows.net/prodavtblobs Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted ---- -------- ------ ----------- ------------ ---------- ------------ --------- sample.jpg BlockBlob 4739 application/octet-stream 2018-11-28 03:51:32Z 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