This decorator checks the file extensions and size. If the file extensions
and size provided by the developer are not in the request.FILES then it
will raise errors. In this way, developers don't need to modify their
functions to check the file validations.
For example,
{{{
@require_files(["pdf", "txt", 20])
def file_upload_view(request):
return HttpResposne("Successful")
}}}
Here this decorator will check if the file types are (pdf or txt) else
will raise TypeError. Also, check if each file size is less than 20 MB.
If not, will raise IOError.
I had already started working on this decorator and had written multiple
tests. So the functionality is almost implemented.
This feature is useful for improving the security and reliability of file
uploads in the project, as it prevents users from uploading files that may
cause server issues or contain malicious content.
--
Ticket URL: <https://code.djangoproject.com/ticket/34441>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* has_patch: 1 => 0
* resolution: => wontfix
Comment:
The current thread is to keep Django a core framework, not providing every
utility which might be useful. Moreover, this is partly covered by
`FileExtensionValidator`, and it's almost a duplicate of your previous
tickets #34263 and #33942.
If you don't agree than first start a discussion on the
DevelopersMailingList, where you'll reach a wider audience and see what
other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets].
--
Ticket URL: <https://code.djangoproject.com/ticket/34441#comment:1>