upload_file#

class starlite.datastructures.upload_file.UploadFile#

Bases: object

Representation of a file upload, modifying the pydantic schema.

__init__(content_type: str, filename: str, file_data: Optional[bytes] = None, headers: Optional[Dict[str, str]] = None, max_spool_size: int = 1048576) None#

Upload file in-memory container.

Parameters:
  • content_type – Content type for the file.

  • filename – The filename.

  • file_data – File data.

  • headers – Any attached headers.

  • max_spool_size – The size above which the temporary file will be rolled to disk.

property rolled_to_disk: bool#

Determine whether the spooled file exceeded the rolled-to-disk threshold and is no longer in memory.

Returns:

A boolean flag

async write(data: bytes) int#

Proxy for data writing.

Parameters:

data – Byte string to write.

Returns:

None

async read(size: int = -1) bytes#

Proxy for data reading.

Parameters:

size – position from which to read.

Returns:

Byte string.

async seek(offset: int) int#

Async proxy for file seek.

Parameters:

offset – start position..

Returns:

None.

async close() None#

Async proxy for file close.

Returns:

None.

classmethod __modify_schema__(field_schema: Dict[str, Any], field: Optional[ModelField]) None#

Create a pydantic JSON schema.

Parameters:
  • field_schema – The schema being generated for the field.

  • field – the model class field.

Returns:

None