Ich benutze Flask send_file
, damit Benutzer eine Zip-Datei herunterladen können. Die Download-Funktion funktioniert, aber jedes Mal, wenn ein Benutzer eine Datei herunterlädt, erstellt er eine doppelte Zip-Datei in meinem my_project/app/
. Ich kann nicht herausfinden, wie die doppelten Dateien erzeugt werden.Flask send_file erzeugt doppelte Dateien
@post_user_blueprint.route('/download_note/<string:ind_id>/', methods=['GET', 'POST'])
def download_note(ind_id):
zip_name = "{0}_notes.zip".format(ind_id)
upload_path = current_app.config['UPLOAD_PATH']
path = os.path.dirname(upload_path + "/documents/" + "/{0}/".format(ind_id))
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(path):
for file in files:
zipf.write(path + '/' + file, basename(path + '/' + file))
zipf.close()
return send_file(zip_name, as_attachment=True)