一、安装
pip install Flask
二、 编写上传文件接口webapi.py
http://127.0.0.1:5000/upload
from flask import Flask,request
from werkzeug.utils import secure_filename
import uuid
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.post('/upload')
def file_upload():
f=request.files['file']
uuid1 =str(uuid.uuid1())
path=uuid1 + f.filename
f.save(f"{secure_filename(f.filename)}")
return '上传成功!'
if __name__ == '__main__':
app.run()
Post调用接口:
curl --location --request POST 'http://127.0.0.1:5000/upload' \
--form 'file=@"/C:/Users/xxx/OneDrive/图片/tos.jpg"'