SimpleUploadedFile
A simple representation of a file, which just has content, size, and a name.
Attributes
| Attribute | Type | Description |
|---|---|---|
| name | string | The name of the file being uploaded. |
| content | bytes or string | The raw binary or string data representing the file's contents. |
| content_type | string = text/plain | The 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
| Name | Type | Description |
|---|---|---|
| name | string | The name of the file. |
| content | bytes | The binary content of the file. |
| content_type | string = "text/plain" | The MIME type of the file content. |
Signature
def SimpleUploadedFile(
name: string,
content: bytes,
content_type: string = text/plain
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The name of the file to be created, including the extension. |
| content | bytes | The binary or text data to be stored in the file; defaults to an empty byte string if None. |
| content_type | string = text/plain | The 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
| Name | Type | Description |
|---|---|---|
| file_dict | dict | A dictionary containing 'filename', 'content', and optionally 'content-type' keys used to construct the file object. |
Returns
| Type | Description |
|---|---|
[SimpleUploadedFile](simpleuploadedfile.md?sid=django_core_files_uploadedfile_simpleuploadedfile) | A new instance of SimpleUploadedFile populated with the data from the dictionary. |