forms: fix image file upload in CachedFileField

This commit is contained in:
Mira Weller
2024-02-20 14:57:00 +01:00
committed by Raphael Michel
parent c6fa19d771
commit 2d5d27e950
2 changed files with 6 additions and 5 deletions

View File

@@ -229,7 +229,7 @@ class ExtValidationMixin:
raise forms.ValidationError(_("Filetype not allowed!"))
if ext in IMAGE_EXTS:
validate_uploaded_file_for_valid_image(data)
validate_uploaded_file_for_valid_image(data if isinstance(data, UploadedFile) else data.file)
return data

View File

@@ -44,11 +44,12 @@ def validate_uploaded_file_for_valid_image(f):
# have to read the data into memory.
if hasattr(f, 'temporary_file_path'):
file = f.temporary_file_path()
elif hasattr(f, 'read'):
if hasattr(f, 'seek') and callable(f.seek):
f.seek(0)
file = BytesIO(f.read())
else:
if hasattr(f, 'read'):
file = BytesIO(f.read())
else:
file = BytesIO(f['content'])
file = BytesIO(f['content'])
try:
try: