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
标签:27,可选项,UploadFile,FastAPI,upload,file,上传
From: https://www.cnblogs.com/leoshi/p/17259061.html