Search code examples
djangoiodjango-imagekit

I/O operation on closed file in django with 'ImageKit'


In my django project I am using ImageKit to size my profile images.

I have a model with these fields:

pasfoto = models.ImageField(upload_to='images/', blank=True)
pasfoto_thumbnail = ImageSpecField(source='pasfoto',
                                      processors=[ResizeToFill(150, 200)],
                                      format='JPEG',
                                      options={'quality': 60})

ImageSpecField is imported from Imagekit.

I am saving my images on amazon-S3 via Django-storages

When I upload an image via the template (edit form) rendered via an UpdateView it shows the detail template after success. The pasfoto_thumbnail is used in this template, that is rendered via a class based DetailView in Django.

In this case I see an error 'I/O operation on closed file'. But after a browser refresh is shows the right image. What is happening and how could I solve this issue?


Django Debug page/info for this error


Solution

  • I recently had the same issue and it was preventing me to upgrade django-storages to the latest version.

    I finally tracked down the issue to this old django-storages issue.

    And in that thread they mention django s3 storages. Migrating to that library seems to fix it.