#34441 closed New feature (wontfix)

A new require_files decorator for file validation in Django Framework

Reported by: Raza Ul Mustafa Owned by: nobody
Component: File uploads/storage Version: 4.1
Severity: Normal Keywords: decorator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am interested in adding a new decorator in Django. This decorator will be used for file validation purposes.

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.

Change History (1)

comment:1 by Mariusz Felisiak, 18 months ago

Has patch: unset
Resolution: wontfix
Status: newclosed

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 follow the triaging guidelines with regards to wontfix tickets.

Note: See TracTickets for help on using tickets.
Back to Top