Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download a file? #59

Open
sliceme opened this issue Nov 30, 2023 · 1 comment
Open

Download a file? #59

sliceme opened this issue Nov 30, 2023 · 1 comment

Comments

@sliceme
Copy link

sliceme commented Nov 30, 2023

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
Copy link

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)})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants