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

Provide a simple way to return files in Mesop app #472

Closed
wwwillchen opened this issue Jun 19, 2024 Discussed in #453 · 3 comments
Closed

Provide a simple way to return files in Mesop app #472

wwwillchen opened this issue Jun 19, 2024 Discussed in #453 · 3 comments
Labels
feature request New feature / API

Comments

@wwwillchen
Copy link
Collaborator

Discussed in #453

Originally posted by herb June 17, 2024
I want to setup a website that takes a URL and returns a PDF based on that URL. Back in the day that means an API endpoint that takes a Json body with the URL and returns a response with content type application/pdf and the contents of the PDF in the body. And then some trivial html form that has a field for the URL.

How do I accomplish this with mesop?

I suspect some of the hangup is the separating line between client and server when writing mesop code. But also how to accomplish the 'download file ' piece is unclear to me.

@wwwillchen wwwillchen added the feature request New feature / API label Jun 19, 2024
@richard-to
Copy link
Collaborator

For this, I'm wondering if we can optionally allow the user to register a download route and let the user implement some function to handle downloads.

For the simple case, we could wrap the Flask send_from_directory for Mesop usage. The issue here is that this function isn't great since it uses the local file system, so not really scalable, but could work basic uses cases. Another potential issue is people accessing other people's data. We could mitigate this a bit if we generated session IDs for users using the builtin Flask session object.

@app.route('/uploads/<path:filename>', methods=['GET', 'POST'])
def download(filename):
    return send_from_directory(directory=app.config['UPLOAD_FOLDER'], filename=filename)

This also goes back to the question of whether want to expose more of the Flask internals or not. Though I lean toward not exposing more internals since I do think we'll likely want to move away from Flask at some point.

Interface maybe something like:

me.register_downloads_route(route_function)

I guess I'm not sure if the Mesop state would be possible to make state accessible from the route function since there could be cases where we just want to serialize data from state for download. Also it seems maybe a bit too specific to register a route specifically for downloads.

@kevinknights29
Copy link

Hi All,

I'm interested in this functionality as well.

Looking forward to more comments on the topic!

@wwwillchen
Copy link
Collaborator Author

@kevinknights29 just posted a response to: #453 (comment) - please take a look and let us know if you have any questions or comments.

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

No branches or pull requests

3 participants