0

I'm trying to get flask to send a trial xlsx file with Ajax. My Javascript code is:

$('#download-button').click(function(event) {
    $.ajax({
        data : {'download_map': 'download_map'},
        type : 'POST',
        url : '/download'
    });
});

And the python looks like:

@app.route('/download', methods=['POST'])
def download():
    file = io.BytesIO()
    wb = Workbook(file)
    ws = wb.add_worksheet()
    ws.write('A1','Hello World')
    wb.close()
    file.seek(0)
    wrapped_file = FileWrapper(file)
    print('Gets here')
    return Response(
        wrapped_file,
        mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        direct_passthrough=True
    )

Although this successfully sends a response, it doesn't allow the user to download the file. Is there something I am missing here?

tewerty
  • 143
  • 1
  • 1
  • 8

0 Answers0