Hi,
I need to make a Python dictionary available as a downloadable JSON file. Since the dictionary can be quite large, I’d like to
stream the response so it downloads in chunks rather than all at once. How can I achieve that?
P.S. The following code works, but it appears to send the entire file in one go rather than streaming it:
json_str = json.dumps(data_dict, indent=2)
response.headers['Content-Type'] = 'application/json' # Removed to force file download
response.headers['Content-Disposition'] = f'attachment; filename=topic_data.json'
return json_str
Thanks!