#Blob Container für Bilder erstellen
az storage container create -n images --account-name sapicana180719 --public-access blob

#Erstellen der Function App Instanz
az functionapp create -n fun-picana1107ku -g rg-pictureanalysis-practice -s sapicana1107ku -c westeurope

#Setzen einer Umgebungsvariablen für den Connection String für Storage Account
export STORAGE_CONNECTION_STRING=$(az storage account show-connection-string -n sapicana1107ku -g rg-pictureanalysis-practice --query "connectionString" --output tsv)
echo $STORAGE_CONNECTION_STRING
az functionapp config appsettings set -n fun-picana1107ku -g rg-pictureanalysis-practice --settings AZURE_STORAGE_CONNECTION_STRING=$STORAGE_CONNECTION_STRING -o table

#CORS im Storage Account einrichten
az storage cors add --methods OPTIONS PUT --origins '*' --exposed-headers '*' --allowed-headers '*' --services b --account-name sapicana1107ku

#App anpassen für den Upload von Bildern
cd ~/functions-first-serverless-web-application/www/dist
export FUNCTION_APP_URL="https://"$(az functionapp show -n fun-picana1107ku -g rg-pictureanalysis-practice --query "defaultHostName" --output tsv)
echo $FUNCTION_APP_URL
echo "window.apiBaseUrl = '$FUNCTION_APP_URL'" > settings.js
cat settings.js

export BLOB_BASE_URL=$(az storage account show -n sapicana1107ku -g rg-pictureanalysis-practice --query primaryEndpoints.blob -o tsv | sed 's/\/$//')
echo $BLOB_BASE_URL
echo "window.blobBaseUrl = '$BLOB_BASE_URL'" >> settings.js
cat settings.js

az storage blob upload -c \$web --account-name sapicana1107ku -f settings.js -n settings.js

#Test: Image anzeigen
az storage blob list --account-name sapicana150918 -c images -o table

#Test: Images aus Blob Container löschen
az storage blob delete-batch -s images --account-name sapicana150918
