Skip to main content

MemoryFileUploadHandler

File upload handler to stream uploads into memory (used for small files).

Attributes

AttributeTypeDescription
activatedbooleanA boolean flag indicating whether the handler is active based on whether the upload size is within the memory limit.
fileBytesIOA BytesIO buffer used to store the uploaded file data in memory when the handler is activated.

Constructor

Signature

def MemoryFileUploadHandler()

Methods


handle_raw_input()

@classmethod
def handle_raw_input(
input_data: file-like object,
META: dict,
content_length: int,
boundary: str,
encoding: str
) - > null

Use the content_length to signal whether or not this handler should be used.

Parameters

NameTypeDescription
input_datafile-like objectThe raw HTTP request body stream to be processed
METAdictThe dictionary of metadata from the request, including headers
content_lengthintThe expected size of the upload in bytes used to determine if it fits in memory
boundarystrThe multipart boundary string used to separate form fields
encodingstrThe character encoding used for the request data

Returns

TypeDescription
nullNone

new_file()

@classmethod
def new_file(
*args: any,
**kwargs: any
) - > null

Initializes a new in-memory byte stream for the file upload if the handler was activated during raw input processing.

Parameters

NameTypeDescription
*argsanyVariable positional arguments passed to the base FileUploadHandler
**kwargsanyVariable keyword arguments passed to the base FileUploadHandler

Returns

TypeDescription
nullNone

receive_data_chunk()

@classmethod
def receive_data_chunk(
raw_data: bytes,
start: int
) - > bytes | null

Add the data to the BytesIO file.

Parameters

NameTypeDescription
raw_databytesThe chunk of byte data received from the upload stream
startintThe starting byte position of this chunk within the file

Returns

TypeDescription
`bytesnull`

file_complete()

@classmethod
def file_complete(
file_size: int
) - > InMemoryUploadedFile | null

Return a file object if this handler is activated.

Parameters

NameTypeDescription
file_sizeintThe total size of the uploaded file in bytes

Returns

TypeDescription
`InMemoryUploadedFilenull`