FileUploadHandler
Base class for streaming upload handlers.
Attributes
| Attribute | Type | Description |
|---|---|---|
| chunk_size | int = 65536 | The default chunk size is 64 KB. |
Constructor
Signature
def FileUploadHandler(
request: object = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| request | object = None | The optional request object associated with the file upload. |
Methods
handle_raw_input()
@classmethod
def handle_raw_input(
input_data: file-like object,
META: dict,
content_length: int,
boundary: str,
encoding: str = None
)
Handle the raw input from the client.
Parameters
| Name | Type | Description |
|---|---|---|
| input_data | file-like object | An object that supports reading via .read() containing the raw stream from the client |
| META | dict | The request.META dictionary containing server and environment metadata |
| content_length | int | The integer value of the Content-Length header provided by the client |
| boundary | str | The multipart boundary string from the Content-Type header, excluding the leading dashes |
| encoding | str = None | The character encoding used for the request body |
new_file()
@classmethod
def new_file(
field_name: str,
file_name: str,
content_type: str,
content_length: int,
charset: str = None,
content_type_extra: dict = None
)
Signal that a new file has been started.
Parameters
| Name | Type | Description |
|---|---|---|
| field_name | str | The name of the HTML form field associated with the file upload |
| file_name | str | The original name of the file as provided by the client |
| content_type | str | The MIME type of the file (e.g., 'image/jpeg') |
| content_length | int | The claimed size of the file; note that this value from the client may be untrustworthy |
| charset | str = None | The character set of the file if specified in the Content-Type header |
| content_type_extra | dict = None | Additional parameters found in the Content-Type header |
receive_data_chunk()
@classmethod
def receive_data_chunk(
raw_data: bytes,
start: int
)
Receive data from the streamed upload parser. start is the position in the file of the chunk.
Parameters
| Name | Type | Description |
|---|---|---|
| raw_data | bytes | The byte string containing a chunk of data from the uploaded file |
| start | int | The byte offset within the file where this specific chunk begins |
file_complete()
@classmethod
def file_complete(
file_size: int
) - > [UploadedFile](../uploadedfile/uploadedfile.md?sid=django_core_files_uploadedfile_uploadedfile)
Signal that a file has completed. File size corresponds to the actual size accumulated by all the chunks.
Parameters
| Name | Type | Description |
|---|---|---|
| file_size | int | The total number of bytes actually received for the file |
Returns
| Type | Description |
|---|---|
[UploadedFile](../uploadedfile/uploadedfile.md?sid=django_core_files_uploadedfile_uploadedfile) | A valid UploadedFile object representing the finished upload |
upload_complete()
@classmethod
def upload_complete()
Signal that the upload is complete. Subclasses should perform cleanup that is necessary for this handler.
upload_interrupted()
@classmethod
def upload_interrupted()
Signal that the upload was interrupted. Subclasses should perform cleanup that is necessary for this handler.