I have multiple json and csv files under the static folder of Web2Py that I'd like to download from the server to local client with a web2py controller and response.stream
. The following controller code works:
def my_download():
directory = '2e6d2ba1-52d7-4927-b91d-c7568b25314d/'
Cat = 'problems'
path=os.path.join(request.folder,'static', directory + Cat + '.json')
return response.stream(open(path,'rb'), attachment=True, filename=Cat)
How to loop thru the other files in directory
, which have Cat = 'foo'
and Cat ='bar'
, etc. and stream / dl all to client?
After the first return response.stream
and successful run, controller doesn't have focus anymore, so it cannot continue execute another return response.stream
or any other statement for that matter (like deleting the files, for example).