Skip to content

Commit e514f8c

Browse files
committed
Fix #26 -- Always open files from storage for processing
1 parent eb4ac33 commit e514f8c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pictures/tasks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313

1414
def _process_picture(field_file: PictureFieldFile) -> None:
15-
field_file.open() # the file needs to be open
16-
with Image.open(field_file.file) as img:
17-
for ratio, sources in field_file.aspect_ratios.items():
18-
for file_type, srcset in sources.items():
19-
for width, picture in srcset.items():
20-
picture.save(img)
15+
# field_file.file may already be closed and can't be reopened.
16+
# Therefore, we always open it from storage.
17+
with field_file.storage.open(field_file.name) as fs:
18+
with Image.open(fs) as img:
19+
for ratio, sources in field_file.aspect_ratios.items():
20+
for file_type, srcset in sources.items():
21+
for width, picture in srcset.items():
22+
picture.save(img)
2123

2224

2325
process_picture = _process_picture

0 commit comments

Comments
 (0)