Home > Net >  Djanog limit image upload size
Djanog limit image upload size

Time:01-09

I am attempting to limit the size of an image that can be uploaded. To do this in the docs I found DATA_UPLOAD_MAX_MEMORY_SIZE I set the value of it to 3mb (3145728 bytes) in my settings.py file but I am still able to upload files larger than 3 mb. I also tried FILE_UPLOAD_MAX_MEMORY_SIZE and the same thing occurred. The only way i can get it to trigger is if i set it to a very low value such as 1 or 2. Any ideas on what I'm doing wrong.

CodePudding user response:

From the docs for DATA_UPLOAD_MAX_MEMORY_SIZE, it does not include uploaded files.

The check is done when accessing request.body or request.POST and is calculated against the total request size excluding any file upload data.

FILE_UPLOAD_MAX_MEMORY_SIZE defines when an uploaded file is saved to the filesystem instead of staying in memory, it does not impose any limits on how large the uploaded file can be

Your best bet is to configure your webserver to limit upload size, client_max_body_size if you are using nginx for example

  •  Tags:  
  • Related