Django gives "I/O operation on closed file" error when reading from a saved ImageField
- by Rob Osborne
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?