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

Commit 232d81b8 by 李景熙

修改上传文件的相关代码

parent b0310f55
......@@ -359,7 +359,7 @@
uploadFile(fileObj){
let formData = new window.FormData();
formData.set("file",fileObj.file);
this.axios("/files/upload",formData,{
this.axios.post("/files/upload",formData,{
headers:{
"Content-type":"multipart/form-data"
}
......
......@@ -2,7 +2,7 @@ from flask import Flask
from flask_cors import CORS
# from views.uploadDownload import uploadDownload
from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation
from views.user import user
from views.task import task
......@@ -18,7 +18,7 @@ app.config.from_object(DevelopmentConfig)
# Image.db.init_app(app)
# app.register_blueprint(textAnnotation)
# app.register_blueprint(uploadDownload)
app.register_blueprint(uploadDownload)
app.register_blueprint(user)
app.register_blueprint(task)
app.register_blueprint(slice)
......
i am a cat
\ No newline at end of file
我是一只小猫咪
\ No newline at end of file
我是一只小猫咪
\ No newline at end of file
我是一只小猫咪
\ No newline at end of file
......@@ -9,9 +9,9 @@ from flask import jsonify, request, send_file
from werkzeug.utils import secure_filename
uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/uploadDownload")
uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/api/files")
UPLOAD_FOLDER = 'upload' # 用于保存上传文件的文件夹名称
ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx'} # 允许上传的文件格式
ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx', 'png', 'jpg', 'bmp', 'gif'} # 允许上传的文件格式
# 用于判断文件后缀
......@@ -22,11 +22,11 @@ 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)
f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值
if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型
fName = secure_filename(f.filename)
ext = fName.rsplit('.', 1)[1] # 获取文件后缀
......
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