Skip to main content

TemporaryFileUploadHandler

Upload handler that streams data into a temporary file.

Attributes

AttributeTypeDescription
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

NameTypeDescription
*argsanyPositional arguments passed to the base FileUploadHandler initialization
**kwargsanyKeyword arguments containing file metadata such as file_name, content_type, and charset

Returns

TypeDescription
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

NameTypeDescription
raw_databytesThe byte string containing a chunk of data from the upload stream
startintThe starting byte position of this chunk within the overall file

Returns

TypeDescription
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

NameTypeDescription
file_sizeintThe total number of bytes received for the uploaded file

Returns

TypeDescription
[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

TypeDescription
null