Can I download file if I get full way to him? And then delete it?
That’s my folders
My jquery in static/js/my_jquery. I need to get file from data/Expenses01.xlsx after ajax.done
$.ajax({
type: "POST",
url: "/create_excel/" + url,
data: JSON.stringify(for_download),
contentType: "application/json; charset=utf-8",
async: false
}).done((response) => {
console.log(response)
});
In response I get full way to file
Flask code which return way, but I think that’s don’t very important
@bp.route('/create_excel/', methods=['POST', 'GET'])
def export_excel():
filename = excel()
print(request.json['Test'])
return redirect(url_for('main.download_file', filename=filename))
@bp.route('/download_file/')
def download_file():
filename = request.args['filename']
return filename
# return send_file(filename, mimetype='text/xlsx', as_attachment=True)
I click button then call ajax which call python function which create file, after I need to download this, return send_file/send_from_dictionary doesn’t work and I want to try download in ajax.done
There’s my project on git:
https://github.com/Danila0987654/Flask_download_files