question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"The file cannot be reopened" when used with Django imagekit

See original GitHub issue

I’m using django-s3-storage along with django-imagekit, but there seems to be a problem with the way django-s3-storage opens files. It’s easy to reproduce, and I have a full django app and repro instructions for the issue, here: https://github.com/mgalgs/iktest

I was a bit thrown off for a while because django-s3-storage isn’t anywhere in the stack trace of the erroneous situation, but @scottmx81 figured out that the test app works fine with django-storages, or by monkey-patching pilkit.open_image like so:

from pilkit.lib import Image
from pilkit import utils


def open_image(target):
    try:
        target.seek(0)
        return Image.open(target)
    except ValueError:
        return Image.open(target.storage.open(target.name))

utils.open_image = open_image

With django-storages no monkey-patch is required…

/cc @scottmx81

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
etianencommented, Nov 2, 2016

Heh, no worries, closing an issue is it’s own reward.

If nobody steps forth to claim it, maybe throw the money at a worthy charity.

0reactions
mgalgscommented, Nov 2, 2016

Fix confirmed! Thank you!!!

If you’d like, feel free to reap this small bounty 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"The file cannot be reopened." error from django-imagekit after ...
I'm using django-imagekit to generate a thumbnail on a Django model: class Book(models.Model): title = models.
Read more >
Template ValueError - The file cannot be reopened. #369
I just tried to use imagekit on a project which stores media on s3, ... The file cannot be reopened. boto==2.39.0 Django==1.8.11 ...
Read more >
django-imagekit - Read the Docs
ImageKit is a Django app for processing images. Need a thumbnail? A black-and-white version of a user-uploaded image? ImageKit will make them for...
Read more >
Is it possible to update ImageSpecField with a source's new file path?
I have a Django model with a picture (ImageField) and then a thumbnail (ImageSpecField) that ... so this fails with a "The file...
Read more >
I/O operation on closed file: Django Imagekit & Pillow-django
The Problem as it can be seen was happening because the file sent by imagekit could not be processed directly by PIL. So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found