1

I want to deploy a functionApp in azure using a zip file which is in another azure blob storage using powershell. I tried like following method

#PowerShell
$username = "<deployment_user>"
$password = "<deployment_password>"
$filePath = "https://xxxxx.blob.core.windows.net/container/zzzz.zip"
$apiUrl = "https://<app_name>.scm.azurewebsites.net/api/zipdeploy"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 
$username, $password)))
$userAgent = "powershell/1.0"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath - ContentType "multipart/form-data"

But I got the following error message like

Invoke-RestMethod : Cannot find drive. A drive with the name 'https' does not exist.

How I do the deployment from a remote url file?

2 Answers 2

1

Since Invoke-RestMethod InFile accepts the content from a file, blob content needs to be explicitly downloaded first.

Option 1

$fileUrl = "https://xxxxx.blob.core.windows.net/container/zzzz.zip"
$token = 'sp=r&st=2019-07-06T21:41:45Z&se=2019-07-07T05:41:45Z&spr=https&sv=2018-03-28&sig=9ud%2FiJ6GBccxZfyrKsZtP69lwuralu1D0QiiESa%2FXgo%3D&sr=b'
$filePath = [System.IO.Path]::GetFileName($fileUrl)
Invoke-WebRequest ('{0}?{1}' -f $fileUrl, $token) -OutFile $filePath  

Prerequisite

Instead of resource Url, SAS (Shared Access Signature) URI needs to be provided which includes a SAS token to perform the authenticated request

Option 2

Via Azure Storage Cmdlets:

$StorageAccountName = 'yourstorageaccount'
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName
$StorageContext = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey.Primary
$FileName = 'zzzz.zip'
$OutputPath = 'C:\Temp'
$ContainerName  = 'yourcontainer'
Get-AzureStorageBlobContent -Blob $FilebName -Container $ContainerName -Destination $OutputPath -Context $StorageContext
Sign up to request clarification or add additional context in comments.

Comments

0
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath - ContentType "multipart/form-data"

-InFile $filePath

param expect the path of file locally.

Check the documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6

Use something like:

  1. First, download the blob from Azure Storage.
  2. Convert into byte stream.
  3. Set as a part of your request (Body).

Sample Code for reference:

$base64Image = [convert]::ToBase64String((get-content $path -encoding byte))

Invoke-WebRequest -uri $uri -Method Post -Body $base64Image -ContentType "application/base64"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.