I am trying out static web pages service from Azure. But I need to access a list of files (for example images stored on the server) from the client side. I am trying to implement a Function that will iterate over the files in a particular folder and return a list of names.
The problem is that I simply cannot access those files. It can't find them from the context in which the Function runs as if they are stored on another machine.
I now use this function to print the folders and files accessible to the python.
This is the function I used called GetResources:
import logging
import os
import sys
import azure.functions as func
import json
import os
def showFolderTree(path):
show_files=True
indentation=1
file_output=False
tree = []
result=""
if not show_files:
for root, dirs, files in os.walk(path):
level = root.replace(path, '').count(os.sep)
indent = ' '*indentation*(level)
tree.append('{}{}/'.format(indent,os.path.basename(root)))
if show_files:
for root, dirs, files in os.walk(path):
level = root.replace(path, '').count(os.sep)
indent = ' '*indentation*(level)
tree.append('{}{}/'.format(indent,os.path.basename(root)))
for f in files:
subindent=' ' * indentation * (level+1)
tree.append('{}{}'.format(subindent,f))
for line in tree:
result+=line+"\n"
return result
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
# logging.info('Python HTTP trigger function processed a request.') --> where is this logged?
try:
errors=context.function_directory+"\n"
except Exception as e:
error="context error\n"
try:
errors+=os.path.dirname(os.path.realpath(__file__))+"\n"
errors+=os.getcwd()+"\n"
errors+=showFolderTree("/")
except Exception as e:
errors+=e
return func.HttpResponse(errors,status_code=200)
This function returns:
/home/site/wwwroot/GetResources
/home/site/wwwroot/GetResources
/home/site/wwwroot
/
app/
.bash_logout
.bashrc
.profile
site/
wwwroot/
.funcignore
requirements.txt
proxies.json
.gitignore
host.json
GetResources/
function.json
sample.dat
__init__.py
__pycache__/
__init__.cpython-38.pyc
.python_packages/
lib/
site-packages/
azure/
functions/
... many many other files
but I cannot find my files in the list. The wwwroot
folder seems to match up with my local api
folder.
What am I doing wrong?
Note: I have a student subscription
Side issue: I cannot find anywhere the logs generated by the Function (generated by the logging function).