From 698bd185b568e159999649b8270166feb47fcb43 Mon Sep 17 00:00:00 2001 From: zhaoyh6 Date: Thu, 23 Sep 2021 11:06:57 +0800 Subject: feat:Add file transfer function Issue-ID: USECASEUI-605 Signed-off-by: zhaoyh6 Change-Id: Ic5429e61c394e2a430fdc5ffc75b2b5fb4744bed --- nlp/scripts/upload.py | 51 +++++++++++++++++++++++++++++++++++++ standalone/src/main/assembly/run.sh | 1 + 2 files changed, 52 insertions(+) create mode 100644 nlp/scripts/upload.py diff --git a/nlp/scripts/upload.py b/nlp/scripts/upload.py new file mode 100644 index 0000000..abc5610 --- /dev/null +++ b/nlp/scripts/upload.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# coding: utf-8 + +# auther = 'zhaoyehua' +# date = 20210918 + + +from flask import Flask, request, render_template +import zipfile +import shutil +import os + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = 'upload/' + +@app.route("/uploader", methods=["POST"]) +def uploader(): + print("aa") + if request.method == 'POST': + f = request.files['file'] + print(f.filename) + f.save(os.path.join(app.config['UPLOAD_FOLDER'], f.filename)) + return "ok" + +@app.route("/unzipFile/", methods=["GET"]) +def unzipFile(fileName): + zip_file = zipfile.ZipFile(os.path.join(app.config['UPLOAD_FOLDER'], fileName)) + parentDir = os.path.join(app.config['UPLOAD_FOLDER'], fileName.split(".zip")[0]) + if os.path.isdir(parentDir): + pass + else: + os.mkdir(parentDir) + for names in zip_file.namelist(): + zip_file.extract(names, parentDir) + zip_file.close() + return parentDir + +@app.route("/deleteFile/", methods=["GET"]) +def deleteFile(fileName): + path = os.path.join(app.config['UPLOAD_FOLDER'], fileName) + if os.path.exists(path): + os.remove(path) + dirPath = path.split(".zip")[0] + if os.path.isdir(dirPath): + shutil.rmtree(dirPath) + return "ok" + return "ok" + return "error: no such file" + +if __name__ == '__main__': + app.run(host="0.0.0.0", port=33013) \ No newline at end of file diff --git a/standalone/src/main/assembly/run.sh b/standalone/src/main/assembly/run.sh index ec7fc66..6ec5f75 100755 --- a/standalone/src/main/assembly/run.sh +++ b/standalone/src/main/assembly/run.sh @@ -27,5 +27,6 @@ cd /home/run/bert-master/ nohup python -u api_squad_online.py 33011 > online.log 2>&1 & nohup python -u api_squad_offline.py 33012 > offline.log 2>&1 & +nohup python -u upload.py 33013 > upload.log 2>&1 & /usr/bin/tf_serving_entrypoint.sh -- cgit 1.2.3-korg