## 后端:
import os from flask import request,jsonify from werkzeug.utils secure_filename Flask,request hashlib time app = Flask(__name__) @app.route('/upload',methods=[GETPOST']) def upload_file(): if request.method == : file = request.files[file] print(file.filename) basepath = os.path.dirname(__file__) # 当前文件所在路径 加密文件名 file_name = md5(file.filename) + ".jpg" upload_path = os.path.join(basepath,1)">static/ 储存路径 (upload_path) file.save(upload_path) 保存文件 dict_data = {message": 上传成功} return jsonify(dict_data) md5(string): ctime = str(time.time()) m = hashlib.md5(bytes(string,encoding=utf-8)) m.update(bytes(ctime,encoding=)) m.hexdigest() if __name__ == __main__: app.run(debug=True)
# 前端 <!DOCTYPE html> <html lang=en"> <head> <Meta charset=UTF-8"> <title>Title</title> </head> <body> <h1>文件上传示例</h1> <form action="" enctype=multipart/form-data' method='> <input type=" name="> <input type=submit" value=上传"> </form> </body> </html>