TemporaryFileUploadHandler
Upload handler that streams data into a temporary file.
Attributes
| Attribute | Type | Description |
|---|---|---|
| file | [TemporaryUploadedFile](../uploadedfile/temporaryuploadedfile.md?sid=django_core_files_uploadedfile_temporaryuploadedfile) | The TemporaryUploadedFile instance used to stream and store incoming upload data on disk. |
Constructor
Signature
def TemporaryFileUploadHandler() - > null
Methods
new_file()
@classmethod
def new_file(
*args: any,
**kwargs: any
) - > null
Create the file object to append to as data is coming in.
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Positional arguments passed to the base FileUploadHandler initialization |
| **kwargs | any | Keyword arguments containing file metadata such as file_name, content_type, and charset |
Returns
| Type | Description |
|---|---|
null |
receive_data_chunk()
@classmethod
def receive_data_chunk(
raw_data: bytes,
start: int
) - > null
Writes a byte string of uploaded data directly to the underlying temporary file.
Parameters
| Name | Type | Description |
|---|---|---|
| raw_data | bytes | The byte string containing a chunk of data from the upload stream |
| start | int | The starting byte position of this chunk within the overall file |
Returns
| Type | Description |
|---|---|
null |
file_complete()
@classmethod
def file_complete(
file_size: int
) - > [TemporaryUploadedFile](../uploadedfile/temporaryuploadedfile.md?sid=django_core_files_uploadedfile_temporaryuploadedfile)
Finalizes the upload by resetting the file pointer to the beginning and updating the file size attribute.
Parameters
| Name | Type | Description |
|---|---|---|
| file_size | int | The total number of bytes received for the uploaded file |
Returns
| Type | Description |
|---|---|
[TemporaryUploadedFile](../uploadedfile/temporaryuploadedfile.md?sid=django_core_files_uploadedfile_temporaryuploadedfile) | The completed temporary file object ready for further processing or storage |
upload_interrupted()
@classmethod
def upload_interrupted() - > null
Cleans up system resources by closing and deleting the temporary file if the upload process is aborted.
Returns
| Type | Description |
|---|---|
null |