Thursday, 3 June 2021

How to set the maximum image size to upload image in django-ckeditor?

I am using django-ckeditor for my project to upload image along with text content.
I used body = RichTextUploadingField(blank=True, null=True) in model. Now I want to restrict the user to upload large size images in content or larger than predefined maximum height/width. I want the uploaded images in content of particular height/weight and size like less then 1mb.

How can I predefine maximum image height and width as well as maximum image size limit?

Is there any way to define it from django-ckeditor configuration?

Or How to resize the uploaded images from content at backend after user submitted the form?

Here is my models.py:

class Post(models.Model):
    STATUS_CHOICES = {
      ('draft', 'Draft'),
      ('published', 'Published'),
    }
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250, unique=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    body = RichTextUploadingField(blank=True, null=True)
    status = models.CharField(max_length=10,
                             choices=STATUS_CHOICES,
                             default='draft')

I tried a lot to solve it but failed.Any suggetion to solve the issue? Thanks in advance.



from How to set the maximum image size to upload image in django-ckeditor?

No comments:

Post a Comment