Skip to main content

SimpleUploadedFile

A simple representation of a file, which just has content, size, and a name.

Attributes

AttributeTypeDescription
namestringThe name of the file being uploaded.
contentbytes or stringThe raw binary or string data representing the file's contents.
content_typestring = text/plainThe MIME type of the file, used for identifying the file format.

Constructor

Signature

def SimpleUploadedFile(
name: string,
content: bytes,
content_type: string = "text/plain"
) - > null

Parameters

NameTypeDescription
namestringThe name of the file.
contentbytesThe binary content of the file.
content_typestring = "text/plain"The MIME type of the file content.

Signature

def SimpleUploadedFile(
name: string,
content: bytes,
content_type: string = text/plain
) - > null

Parameters

NameTypeDescription
namestringThe name of the file to be created, including the extension.
contentbytesThe binary or text data to be stored in the file; defaults to an empty byte string if None.
content_typestring = text/plainThe MIME type of the file content used for HTTP headers and validation.

Methods


from_dict()

@classmethod
def from_dict(
file_dict: dict
) - > [SimpleUploadedFile](simpleuploadedfile.md?sid=django_core_files_uploadedfile_simpleuploadedfile)

Create a SimpleUploadedFile object from a dictionary with keys: - filename - content-type - content

Parameters

NameTypeDescription
file_dictdictA dictionary containing 'filename', 'content', and optionally 'content-type' keys used to construct the file object.

Returns

TypeDescription
[SimpleUploadedFile](simpleuploadedfile.md?sid=django_core_files_uploadedfile_simpleuploadedfile)A new instance of SimpleUploadedFile populated with the data from the dictionary.