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
648
649
650
651
652
653
654
655
656
657
658
659
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
669
670
671
672
673
674
675
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
677
678
679
680
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
682
683
684
685
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
687
688
689
690
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