文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 29108bba by 李景熙

修改上传文件的相关代码,将数据库配置统一移到model文件中

parent fedc9736
......@@ -367,7 +367,7 @@
if(res.code == 0)
alert("文件上传失败,请重新上传");
else{
console(res.data.url);
console(res.data);
}
})
},
......
from peewee import *
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
from Dao.model import mysql
class Data(Model):
......
from peewee import *
from Dao.model import mysql
import datetime
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Result:
code: int
......
from Dao import Task
from peewee import *
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
from Dao.model import mysql
class Result:
code: int
......
......@@ -2,17 +2,7 @@ from peewee import *
import datetime
import math
from Dao import User
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
from Dao.model import mysql
class Result:
code: int
......
from peewee import *
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
from Dao.model import mysql
class Result:
code: int
......@@ -175,7 +165,5 @@ def get_username(id):
return tmp.userName
if __name__ == '__main__':
register('admin', 'admin', 'admin')
set_type(3, 1)
# User.create_table()
User.create_table()
from flask import Flask
from flask_cors import CORS
from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation
from views.user import user
......@@ -11,6 +9,7 @@ from views.slice import slice
from config.config import DevelopmentConfig
app = Flask(__name__)
CORS(app)
app.config.from_object(DevelopmentConfig)
......
......@@ -22,7 +22,6 @@ def allowed_file(filename):
# 上传文件
@uploadDownload.route('/upload', methods=['POST'], strict_slashes=False)
def upload():
print("1")
file_dir = os.path.join(basedir, UPLOAD_FOLDER)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
......@@ -33,12 +32,9 @@ def upload():
unix_time = int(time.time())
new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名
f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
print(new_filename)
return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename})
return jsonify({"code": 1, "msg": "succeed ", "data": "http://127.0.0.1:9100/api/files/download/"+new_filename})
else:
return jsonify({"errno": 1001, "errmsg": u"failed"})
return jsonify({"code": 0, "errmsg": u"failed"})
# 下载接口
@uploadDownload.route('/download/<fileName>', methods=['GET'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment