Skip to content

Commit

Permalink
Fix #26 -- Always open files from storage for processing
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Aug 6, 2022
1 parent eb4ac33 commit e514f8c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pictures/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@


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


process_picture = _process_picture
Expand Down

0 comments on commit e514f8c

Please sign in to comment.