From f0d6c92db73820e119078814f9ddf1e3bd6c85c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Thuret?= Date: Sun, 24 Oct 2021 18:38:35 +0200 Subject: [PATCH] create download_file route --- app/app.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/app.py b/app/app.py index e32ea1e..a7d4505 100644 --- a/app/app.py +++ b/app/app.py @@ -6,7 +6,7 @@ from functools import wraps import argostranslatefiles import pkg_resources from argostranslatefiles import get_supported_formats -from flask import Flask, abort, jsonify, render_template, request +from flask import Flask, abort, jsonify, render_template, request, url_for from flask_swagger import swagger from flask_swagger_ui import get_swaggerui_blueprint from translatehtml import translate_html @@ -590,15 +590,23 @@ def create_app(args): file.save(filepath) translated_file_path = argostranslatefiles.translate_file(src_langs[0].get_translation(tgt_lang), filepath) - + translated_filename = os.path.basename(translated_file_path) return jsonify( { - "translatedFileUrl": translated_file_path + "translatedFileUrl": url_for('download_file', filename=translated_filename) } ) except Exception as e: abort(500, description=e) + @app.route("/download_file/", methods=["GET"]) + @access_check + def download_file(filename): + """ + Download a translated file + """ + print('') + @app.route("/detect", methods=["POST"]) @access_check def detect():