pimoroni / phew

MIT License
204 stars 44 forks source link

Download a file? #59

Open r0uted opened 12 months ago

r0uted commented 12 months ago

How do I download a file? I want to show all files in .html When use press one file, web server should be able to send that file so user can download.

i can only stream the log files and other files. But i need option to download files too.

Any help? thanks

jkitchin commented 4 months ago

This works for me:

@server.route('/db', methods=['GET'])
def download_db(request):
    with open('database.txt', 'r') as f:
        content = f.read()
        return server.Response(body=content,
                               status=200,
                               headers={"Content-Disposition": "attachment;filename=db.csv",
                               "Content-Type": "text/csv",
                               "Content-Length": len(content)})