Skip to main content

InMemoryUploadedFile

A file uploaded into memory (i.e. stream-to-memory).

Attributes

AttributeTypeDescription
field_namestringThe 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

NameTypeDescription
filefile-like objectThe file-like object containing the uploaded content.
field_namestringThe name of the form field in the HTTP request.
namestringThe name of the uploaded file.
content_typestringThe content type of the file (e.g., text/plain or image/jpeg).
sizeintegerThe size of the uploaded file in bytes.
charsetstringThe character set of the file (e.g., utf-8).
content_type_extradict = NoneExtra 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

NameTypeDescription
filefile-like objectThe underlying file-like object containing the uploaded content
field_namestringThe name of the form field that provided the file upload
namestringThe original filename provided by the client
content_typestringThe MIME type of the file, such as 'image/jpeg'
sizeintegerThe size of the file in bytes
charsetstringThe character set of the file if it is a text-based format
content_type_extradictAdditional 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

NameTypeDescription
modestring = nullThe mode in which to open the file; currently ignored as the file is already in memory

Returns

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

NameTypeDescription
chunk_sizeinteger = nullThe desired size of each chunk in bytes; ignored because the entire file is yielded at once

Returns

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

NameTypeDescription
chunk_sizeinteger = nullThe threshold size used to determine if multiple chunks are necessary

Returns

TypeDescription
booleanAlways returns False because the file is stored entirely in memory and does not require chunked iteration