Hi,
I have very large files my users need to download. They get generated on the fly using a generator.
Using a generator has the advantage of the download starting immediately as the content is created, instead of (the poorer user experience of) making them wait for the entire file to be created before the download starts. It’s also a lot easier on memory requirements.
Here’s what I hoped would work:
def generate():
df = pd....
yield df.to_csv(index=True)
@anvil.server.http_endpoint("/my-end-point")
def get_download(
response = anvil.server.HttpResponse(200)
csv_filename = 'test.csv'
response.headers['Content-Disposition'] = f'attachment; filename="{csv_filename}"'
response.body = generate()
return response
I also looked into using a Media object but couldn’t get that to work either.
So … is there a way to pass a generator (yield) into either a download endpoint response or a media object?
Thanks.