Django gives "I/O operation on closed file" error when reading from a saved ImageField

Posted by Rob Osborne on Stack Overflow See other posts from Stack Overflow or by Rob Osborne
Published on 2010-06-12T20:29:16Z Indexed on 2010/06/12 20:32 UTC
Read the original article Hit count: 281

Filed under:
|

I have a model with two image fields, a source image and a thumbnail.

When I update the new source image, save it and then try to read the source image to crop/scale it to a thumbnail I get an "I/O operation on closed file" error from PIL.

If I update the source image, don't save the source image, and then try to read the source image to crop/scale, I get an "attempting to read from closed file" error from PIL.

In both cases the source image is actually saved and available in later request/response loops.

If I don't crop/scale in a single request/response loop but instead upload on one page and then crop/scale in another page this all works fine.

This seems to be a cached buffer being reused some how, either by PIL or by the Django file storage. Any ideas on how to make an ImageField readable after saving?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models