CookBook - Validate an image weight

django version : POST-MR

To check the weight an image uploaded via your form, you can implement this method into your view.py or custom manipulator.

Code

Here we check that the image under 100 kb.

def isValideSize(field_data, all_data):
        if len(all_data["image_file"]["content"]) > 100000: # 100,000 bytes 
                raise validators.ValidationError, "File is too large"

Older versions of Django

django version : 0.91

Code

Here we check that the image under 100 kb.

def isValideSize(field_data, all_data):
        if len(field_data["content"]) > 100000: # 100,000 bytes 
                raise validators.ValidationError, "File is too large"
Last modified 9 years ago Last modified on 07/25/2006 10:24:31 AM
Back to Top