InMemoryUploadedFile
A file uploaded into memory (i.e. stream-to-memory).
Attributes
| Attribute | Type | Description |
|---|---|---|
| field_name | string | The name of the form field used to upload the file, used to identify the source input in the request. |
Constructor
Signature
def InMemoryUploadedFile(
file: file-like object,
field_name: string,
name: string,
content_type: string,
size: integer,
charset: string,
content_type_extra: dict = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| file | file-like object | The file-like object containing the uploaded content. |
| field_name | string | The name of the form field in the HTTP request. |
| name | string | The name of the uploaded file. |
| content_type | string | The content type of the file (e.g., text/plain or image/jpeg). |
| size | integer | The size of the uploaded file in bytes. |
| charset | string | The character set of the file (e.g., utf-8). |
| content_type_extra | dict = None | Extra parameters for the content-type header. |
Signature
def InMemoryUploadedFile(
file: file-like object,
field_name: string,
name: string,
content_type: string,
size: integer,
charset: string,
content_type_extra: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| file | file-like object | The underlying file-like object containing the uploaded content |
| field_name | string | The name of the form field that provided the file upload |
| name | string | The original filename provided by the client |
| content_type | string | The MIME type of the file, such as 'image/jpeg' |
| size | integer | The size of the file in bytes |
| charset | string | The character set of the file if it is a text-based format |
| content_type_extra | dict | Additional parameters for the Content-Type header, such as file encoding |
Methods
open()
@classmethod
def open(
mode: string = null
) - > [InMemoryUploadedFile](inmemoryuploadedfile.md?sid=django_core_files_uploadedfile_inmemoryuploadedfile)
Resets the file pointer to the beginning of the stream and returns the file instance for reading.
Parameters
| Name | Type | Description |
|---|---|---|
| mode | string = null | The mode in which to open the file; currently ignored as the file is already in memory |
Returns
| Type | Description |
|---|---|
[InMemoryUploadedFile](inmemoryuploadedfile.md?sid=django_core_files_uploadedfile_inmemoryuploadedfile) | The current instance with the file pointer reset to the start |
chunks()
@classmethod
def chunks(
chunk_size: integer = null
) - > generator
Yields the entire content of the file as a single chunk after resetting the file pointer.
Parameters
| Name | Type | Description |
|---|---|---|
| chunk_size | integer = null | The desired size of each chunk in bytes; ignored because the entire file is yielded at once |
Returns
| Type | Description |
|---|---|
generator | A generator yielding the full byte content of the in-memory file |
multiple_chunks()
@classmethod
def multiple_chunks(
chunk_size: integer = null
) - > boolean
Indicates whether the file is large enough to require multiple chunks for processing.
Parameters
| Name | Type | Description |
|---|---|---|
| chunk_size | integer = null | The threshold size used to determine if multiple chunks are necessary |
Returns
| Type | Description |
|---|---|
boolean | Always returns False because the file is stored entirely in memory and does not require chunked iteration |