Skip to content

Simplify support for JPG/JPEG uploads #13127

Open
@thibaudcolas

Description

@thibaudcolas

Is your proposal related to a problem?

For JPEG files, both the .jpg and .jpeg file extensions are in use in the wild. Our WAGTAILIMAGES_EXTENSIONS setting treats them as separate extensions (as they are), which can create friction / confusion when the setting is used incorrectly: if it only contains jpg, all .jpeg files will fail to upload. This doesn’t seem like a particularly useful behavior as the files are identical anyway.

Describe the solution you'd like

We could make our file extension checker cleverer, so even if only jpg or jpeg are included, images can be uploaded with either extensions?

def get_allowed_image_extensions():
return getattr(
settings,
"WAGTAILIMAGES_EXTENSIONS",
["avif", "gif", "jpg", "jpeg", "png", "webp"],
)
def ImageFileExtensionValidator(value):
# This makes testing different values of WAGTAILIMAGES_EXTENSIONS easier:
# if WagtailImageField.default_validators
# = FileExtensionValidator(get_allowed_image_extensions())
# then the formats that will pass validation are fixed at the time the class
# is created, so changes to WAGTAILIMAGES_EXTENSIONS via override_settings
# has no effect.
return FileExtensionValidator(get_allowed_image_extensions())(value)

Describe alternatives you've considered

Or we could update our documentation so the canonical example reflects the need to use both jpg and jpeg.

Additional context

(Write your answer here.)

Working on this

Anyone can contribute to this. View our contributing guidelines, add a comment to the issue once you’re ready to start.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions