core.files.uploadhandler.FileUploadHandler

class FileUploadHandler [source] All file upload handlers should be subclasses of django.core.files.uploadhandler.FileUploadHandler. You can define upload handlers wherever you wish.

core.files.uploadedfile.UploadedFile.size

UploadedFile.size The size, in bytes, of the uploaded file.

core.files.uploadedfile.UploadedFile.content_type

UploadedFile.content_type The content-type header uploaded with the file (e.g. text/plain or application/pdf). Like any data supplied by the user, you shouldn’t trust that the uploaded file is actually this type. You’ll still need to validate that the file contains the content that the content-type header claims – “trust but verify.”

core.files.uploadedfile.UploadedFile.content_type_extra

UploadedFile.content_type_extra A dictionary containing extra parameters passed to the content-type header. This is typically provided by services, such as Google App Engine, that intercept and handle file uploads on your behalf. As a result your handler may not receive the uploaded file content, but instead a URL or other pointer to the file. (see RFC 2388 section 5.3).

core.files.uploadedfile.TemporaryUploadedFile.temporary_file_path()

TemporaryUploadedFile.temporary_file_path() [source] Returns the full path to the temporary uploaded file.

core.files.uploadedfile.UploadedFile

class UploadedFile [source] During file uploads, the actual file data is stored in request.FILES. Each entry in this dictionary is an UploadedFile object (or a subclass) – a simple wrapper around an uploaded file. You’ll usually use one of these methods to access the uploaded content:

core.files.uploadedfile.InMemoryUploadedFile

class InMemoryUploadedFile [source] A file uploaded into memory (i.e. stream-to-memory). This class is used by the MemoryFileUploadHandler.

core.files.uploadedfile.UploadedFile.chunks()

UploadedFile.chunks(chunk_size=None) A generator returning chunks of the file. If multiple_chunks() is True, you should use this method in a loop instead of read(). In practice, it’s often easiest simply to use chunks() all the time. Looping over chunks() instead of using read() ensures that large files don’t overwhelm your system’s memory. Here are some useful attributes of UploadedFile:

core.files.uploadedfile.TemporaryUploadedFile

class TemporaryUploadedFile [source] A file uploaded to a temporary location (i.e. stream-to-disk). This class is used by the TemporaryFileUploadHandler. In addition to the methods from UploadedFile, it has one additional method:

core.files.uploadedfile.UploadedFile.charset

UploadedFile.charset For text/* content-types, the character set (i.e. utf8) supplied by the browser. Again, “trust but verify” is the best policy here. Note Like regular Python files, you can read the file line-by-line simply by iterating over the uploaded file: for line in uploadedfile: do_something_with(line) Lines are split using universal newlines. The following are recognized as ending a line: the Unix end-of-line convention '\n', the Windows convention '\r\n', and the old Macint