mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-23 13:30:01 -05:00
* ✨ Add support for UploadFile annotations * 📝 Update File upload docs with FileUpload class * ✅ Add tests for UploadFile support * 📝 Update UploadFile docs
16 lines
499 B
Python
16 lines
499 B
Python
from typing import Any, Callable, Iterable, Type
|
|
|
|
from starlette.datastructures import UploadFile as StarletteUploadFile
|
|
|
|
|
|
class UploadFile(StarletteUploadFile):
|
|
@classmethod
|
|
def __get_validators__(cls: Type["UploadFile"]) -> Iterable[Callable]:
|
|
yield cls.validate
|
|
|
|
@classmethod
|
|
def validate(cls: Type["UploadFile"], v: Any) -> Any:
|
|
if not isinstance(v, StarletteUploadFile):
|
|
raise ValueError(f"Expected UploadFile, received: {type(v)}")
|
|
return v
|