首页 > 其他分享 >[FastAPI-27]上传文件为可选项

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

时间:2023-03-26 17:45:11浏览次数:41  
标签:27 可选项 UploadFile FastAPI upload file 上传

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

相关文章

  • 为什么Integer用==比较时127相等而128不相等?
    首先回顾一下自动装箱。对于下面这行代码:Integera=1;变量a为Integer类型,而1为int类型,且Integer和int之间并无继承关系,按照Java的一般处理方法,这行代码应该报错。但因......
  • [FastAPI-24]jsonable_encoder 序列化
    importtypingimportjsonfromfastapiimportFastAPI,Responsefromfastapi.encodersimportjsonable_encoderfromdatetimeimportdatetimefrompydanticimpor......
  • [FastAPI-23]响应体pydantic dict方法
    importtypingfromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()'''pydanticd......
  • P3527 [POI2011]MET-Meteors
    简要题意有\(n\)个国家和有\(m\)段的环形轨道。轨道的第\(i\)段有第\(o_i\)个国家建立的空间站。有\(k\)个时刻,第\(i\)个时刻会在\([l_i,r_i]\)的轨道中......
  • 宝塔上部署FastAPI的步骤和一些注意点
    为了运维方便,选择直接用宝塔来管理pythonfastapi的项目,虽然直接部署可能性能更好更灵活,但是我选择了低层本,每个人的选择可能是不一样的,各有考虑吧。 本文的大逻辑是先......
  • [FastAPI-22]响应模型-response_model
    importtypingfromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()'''响应模型s......
  • [FastAPI-21]响应体
    fromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()classUser(BaseModel):u......
  • HJ27_查找兄弟单词——哈希表查找
    思路:#先找出兄弟单词,按字典排序;输出第k个字典序单词,若没有则不用输出。关键是理解题目兄弟单词的定义。可通过测试案例明确兄弟单词单词定义。如刚开始我的check,只是用se......
  • [FastAPI-20]设置响应头
    fromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()classUser(BaseModel):u......
  • 「Gym102759B」Cactus Competition 题解
    传送门「Gym102759B」CactusCompetition题目大意有一个\(n\timesm\)的网格图,一个长度为\(n\)的序列\(a\),和一个长度为\(m\)的序列\(b\)。网格图中,第\(i\)......