I'm trying to send an excel file back to the user's browser in a zipped folder.
I build the excel file(s) using openpyxl , and here is my code :
@app.route('/test', methods=['GET', 'POST'])
def test():
# ...
from zipfile import ZipFile
# ...
buf = BytesIO()
wb.save(buf)
buf.seek(0)
with ZipFile(buf, 'w') as myzip:
myzip.write(buf, arcname='test.xlsx')
return send_file(myzip, attachment_filename='folder.zip', as_attachment=True)
However, i get the following error:
TypeError: stat: path should be string, bytes, os.PathLike or integer, not _io.BytesIO
How can i do this without using a bytesio object? or can i modify the code so it can accommodate a bytesio object?
many thanks in advance.