Skip to content

UploadFile class

This is the reference for the main object UploadFile that contains all the parameters, attributes and functions.

esmerald.UploadFile

UploadFile(*, file, size=None, filename=None, headers=None)

Bases: DataUpload

Adding pydantic specific functionalitty for parsing.

PARAMETER DESCRIPTION
file

TYPE: BinaryIO

size

TYPE: int | None DEFAULT: None

filename

TYPE: str | None DEFAULT: None

headers

TYPE: Header | None DEFAULT: None

Source code in lilya/datastructures.py
641
642
643
644
645
646
647
648
649
650
651
652
def __init__(
    self,
    *,
    file: BinaryIO,
    size: int | None = None,
    filename: str | None = None,
    headers: Header | None = None,
) -> None:
    self.filename = filename
    self.size = size
    self.headers = headers or Header()
    self.file = file

filename instance-attribute

filename = filename

size instance-attribute

size = size

headers instance-attribute

headers = headers or Header()

file instance-attribute

file = file

content_type property

content_type

in_memory property

in_memory

write async

write(data)
PARAMETER DESCRIPTION
data

TYPE: bytes

Source code in lilya/datastructures.py
662
663
664
665
666
667
668
async def write(self, data: bytes) -> int:
    if self.size is not None:
        self.size += len(data)

    if self.in_memory:
        return await run_sync(self.file.write, data)
    return self.file.write(data)

read async

read(size=-1)
PARAMETER DESCRIPTION
size

TYPE: int DEFAULT: -1

Source code in lilya/datastructures.py
670
671
672
673
async def read(self, size: int = -1) -> bytes:
    if self.in_memory:
        return self.file.read(size)
    return await run_sync(self.file.read, size)

seek async

seek(offset)
PARAMETER DESCRIPTION
offset

TYPE: int

Source code in lilya/datastructures.py
675
676
677
678
async def seek(self, offset: int) -> int:
    if self.in_memory:
        return await run_sync(self.file.seek, offset)
    return self.file.seek(offset)

close async

close()
Source code in lilya/datastructures.py
680
681
682
683
async def close(self) -> int:
    if self.in_memory:
        return await run_sync(self.file.close)
    return self.file.close()

validate classmethod

validate(v)
PARAMETER DESCRIPTION
v

TYPE: Any

Source code in esmerald/datastructures/base.py
60
61
62
63
64
@classmethod
def validate(cls: Type["UploadFile"], v: Any) -> Any:
    if not isinstance(v, LilyaUploadFile):
        raise ValueError(f"Expected UploadFile, got: {type(v)}")
    return v