import typing
from fastapi import FastAPI, File, UploadFile
app = FastAPI(title="Form表单")
'''
上传文件为可选项
'''
@app.post("/upload_large_file", summary="上传大文件")
# 文件可选
# def upload_large_file(file: UploadFile = File(default=None)):
def upload_large_file(file: typing.Optional[UploadFile] = None):
if not file:
return {"data":"no file"}
else:
return file.filename
[FastAPI-27]上传文件为可选项
发布时间 2023-03-26 17:43:54作者: LeoShi2020