MemoryFileUploadHandler
File upload handler to stream uploads into memory (used for small files).
Attributes
| Attribute | Type | Description |
|---|---|---|
| activated | boolean | A boolean flag indicating whether the handler is active based on whether the upload size is within the memory limit. |
| file | BytesIO | A 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
| Name | Type | Description |
|---|---|---|
| input_data | file-like object | The raw HTTP request body stream to be processed |
| META | dict | The dictionary of metadata from the request, including headers |
| content_length | int | The expected size of the upload in bytes used to determine if it fits in memory |
| boundary | str | The multipart boundary string used to separate form fields |
| encoding | str | The character encoding used for the request data |
Returns
| Type | Description |
|---|---|
null | None |
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
| Name | Type | Description |
|---|---|---|
| *args | any | Variable positional arguments passed to the base FileUploadHandler |
| **kwargs | any | Variable keyword arguments passed to the base FileUploadHandler |
Returns
| Type | Description |
|---|---|
null | None |
receive_data_chunk()
@classmethod
def receive_data_chunk(
raw_data: bytes,
start: int
) - > bytes | null
Add the data to the BytesIO file.
Parameters
| Name | Type | Description |
|---|---|---|
| raw_data | bytes | The chunk of byte data received from the upload stream |
| start | int | The starting byte position of this chunk within the file |
Returns
| Type | Description |
|---|---|
| `bytes | null` |
file_complete()
@classmethod
def file_complete(
file_size: int
) - > InMemoryUploadedFile | null
Return a file object if this handler is activated.
Parameters
| Name | Type | Description |
|---|---|---|
| file_size | int | The total size of the uploaded file in bytes |
Returns
| Type | Description |
|---|---|
| `InMemoryUploadedFile | null` |