当前位置 : 主页 > 编程语言 > python >

python3 flask 编写上传文件接口

来源:互联网 收集:自由互联 发布时间:2022-09-02
依赖环境:python3 依赖包:flask,pyOpenSSL(pip install flask pyOpenSSL) #coding=utf-8 import os from flask import Flask, redirect, url_for, request, render_template, send_from_directory import time app = Flask(__name__) BASE_PAT

依赖环境:python3

依赖包:flask,pyOpenSSL(pip install flask pyOpenSSL)

#coding=utf-8
import os
from flask import Flask, redirect, url_for, request, render_template, send_from_directory
import time
app = Flask(__name__)
BASE_PATH = '/tmp/tmp_file/'

@app.route("/upload",methods=["POST"])
def upload_file():
try:
f=request.files["file"]

filename = os.path.join(BASE_PATH,"",f.filename)
f.save(filename)
print("{0} file upload succcessfully!".format(filename))
time.sleep(1)
return "file upload successfully!"
except Exception as e:
return e




if __name__ == '__main__':
app.run(host="0.0.0.0",port="5555",debug=False,ssl_context="adhoc")

  



上一篇:python selenium 下载安装(一)
下一篇:没有了
网友评论