Dipo
Dipo

Reputation: 132

How to access Azure App Service folders from Function App

Is possible to access folders in the Azure App Service from the function App?

I deployed a web application on the app service, and I needed to access the saved documents from the function app.

Is it possible, and if so, kindly state.

Upvotes: 0

Views: 663

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

You can have a try using Kudu rest api to access the folders in the Azure App Service from the function App. See below example to get a file via rest api.

$srcResGroupName = "ResGroupName"
$srcWebAppName = "WebAppName"
$filePath = "/site/wwwroot/myFolder/myfile.json"


# Get publishing profile for SOURCE application
$srcWebApp = Get-AzWebApp -Name $srcWebAppName -ResourceGroupName $srcResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $srcWebApp
# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$apiBaseUrl = "https://$($srcWebApp.Name).scm.azurewebsites.net/api/vfs"
# Download the saved file.
Invoke-RestMethod -Uri "$apiBaseUrl$($filePath)" `
                    -Headers @{UserAgent="powershell/1.0"; `
                     Authorization=("Basic {0}" -f $base64AuthInfo)} `
                    -Method GET `
                    -OutFile ./myfile.json

You can check out this thread for more examples.

Update:

You can check out this document to create a PowerShell function in Azure.

To run above powershell script at intervals. You need to set the Timer trigger for Azure Functions. Please checkout this tutorial.

Upvotes: 1

Related Questions