I want to limit the size of image(Base64) saved to the database. For example, I want the maximum size of image to be 100KB, how can I do that? I'm using Django.
Asked
Active
Viewed 295 times
1 Answers
1
class CreateForm(forms.ModelForm):
#the size you want it to be, example for 2 mb is given below
max_upload_limit = 2*1024*1024
#override clean function to something like this
clean(self):
cleaned_data = super().clean()
pic = cleaned_data.get('picture')
if pic is None:
return
if len(pic) > self.max_upload_limit:
self.add_error('picture', "File must be < "+self.max_upload_limit_text+" bytes")
This show how to restrict image size using Django form.

prathap sagar
- 121
- 8