I am using python 3.5 and flask 0.10.1 and love it, but have few problems with send_file. Ultimately, I want to process the pandas framework (from the form data, which is not used in this example, but is needed in the future) and send it for download as csv (without a temporary file). The best way to achieve this I have seen StringIO for us.
Here is the code I'm trying to use:
@app.route('/test_download', methods = ['POST'])
def test_download():
buffer = StringIO()
buffer.write('Just some letters.')
buffer.seek(0)
return send_file(buffer, as_attachment = True,\
attachment_filename = 'a_file.txt', mimetype = 'text/csv')
Downloading a file with the appropriate name, but the file is completely empty.
Any ideas? Encoding problems? Did they get the answer elsewhere? Thank!
source
share