how to respond to client/browser with a file download #453
-
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 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. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
There isn't a great way to do this right now, but you can create a download link by creating a base-64 encoded data URL, e.g. me.html("""
<a href="data:application/json,%7B%22a%22%3A%20%22hello%22%7D" download="data.json">Download JSON</a>
""") Example: https://colab.research.google.com/drive/11W3QS7zzj43s5vymNegOc3lfRzvupNWR?usp=sharing I've filed a feature request: #472 to provide a first-class way of doing this. |
Beta Was this translation helpful? Give feedback.
-
thanks for the response. will take a look at the alternative you're suggesting. |
Beta Was this translation helpful? Give feedback.
-
We just added support in https://github.com/google/mesop/releases/tag/v0.12.3 for mounting other web servers with Mesop, which means you could use a web framework like FastAPI or Flask and use that to serve the HTTP download endpoints. Here's the guide: https://google.github.io/mesop/guides/server-integration/ |
Beta Was this translation helpful? Give feedback.
We just added support in https://github.com/google/mesop/releases/tag/v0.12.3 for mounting other web servers with Mesop, which means you could use a web framework like FastAPI or Flask and use that to serve the HTTP download endpoints. Here's the guide: https://google.github.io/mesop/guides/server-integration/