[FastAPI-27]上传文件为可选项

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
posted @ 2023-03-26 17:38  LeoShi2020  阅读(111)  评论(0)    收藏  举报