[FastAPI Docs] 폼 및 파일 요청

JeongChaeJin·2022년 9월 1일
0
  • File + Form으로 함께 정의할 수 있다.
pip install python-multipart
from fastapi import FastAPI, File, Form, UploadFile

app = FastAPI()


@app.post("/files/")
async def create_file(
    file: bytes = File(), fileb: UploadFile = File(), token: str = Form()
):
    return {
        "file_size": len(file),
        "token": token,
        "fileb_content_type": fileb.content_type,
    }
  • 파일 받을 때, JSON으로 받아야하는 Body 필드 함께 선언할 수 없음에 유의하자.
profile
OnePunchLotto

0개의 댓글

관련 채용 정보