728x90
반응형

FileForm 을 사용하여 파일 및 폼 필드를 동시에 정의할 수 있습니다.

 

정보

업로드된 파일 그리고/또는 폼 데이터를 전달 받기 위해서는, 우선 python-multipart 를 설치하기 바랍니다.

예를 들어 pip install python-multipart 와 같은 방식으로 가능합니다.

 

FileForm 임포트

 

FileForm 매개변수 정의

Body 또는 Query 와 동일한 방법으로 파일 및 폼 매개변수를 생성합니다.

 

 

파일과 폼 필드는 폼 데이터로 업로드되고 파일 및 폼 필드를 전달 받을 수 있습니다.

 

그리고 몇몇의 파일은 bytes 로 선언하고 다른 몇몇은 UploadFile 로 선언할 수 있습니다.

 

주의

경로 동작 내부에 다중 File 및 Form 매개변수를 선언할 수 있지만, application/json 대신 multipart/form-data 를 사용하여 부호화된 바디가 있기 때문에, JSON으로 전달 받을 것이라 예상되는 Body 필드를 선언할 수는 없습니다.

이것은 FastAPI의 한계가 아닌, HTTP 프로토콜에 관한 부분입니다.

 

요약

동일한 요청 속에서 데이터와 파일을 전달 받아야 한다면 FileForm 을 함께 사용하기 바랍니다.

 


원문

https://fastapi.tiangolo.com/tutorial/request-forms-and-files/

 

Request Forms and Files - FastAPI

Request Forms and Files You can define files and form fields at the same time using File and Form. Info To receive uploaded files and/or form data, first install python-multipart. E.g. pip install python-multipart. Import File and Form from fastapi import

fastapi.tiangolo.com

728x90
반응형

'FastAPI > Tutorial - User Guide' 카테고리의 다른 글

[ FastAPI ] 경로 동작 구성  (0) 2021.10.01
[ FastAPI ] 오류 처리  (0) 2021.09.30
[ FastAPI ] 요청 파일  (0) 2021.09.27
[ FastAPI ] 폼 데이터  (0) 2021.09.25
[ FastAPI ] 응답 상태 코드  (0) 2021.09.25