Skip to content

Restrict the accepted file types in the browser#273

Merged
zerolab merged 2 commits into
torchbox:mainfrom
jsma:restrict-accept-types
Feb 18, 2026
Merged

Restrict the accepted file types in the browser#273
zerolab merged 2 commits into
torchbox:mainfrom
jsma:restrict-accept-types

Conversation

@jsma

@jsma jsma commented Dec 28, 2025

Copy link
Copy Markdown
Contributor

Previously the FileInput widget allowed all file types, which meant the user could select any file and then only find out it's not accepted after uploading. This ensures the FileInput only accepts the listed file extensions or in the absence of file extensions, restricts to audio/video files as appropriate.

While https://github.com/torchbox/wagtailmedia/pull/140/files handled server side validation, this complements that work by restricting the file types on the client side.

Previously the `FileInput` widget allowed all file types, which meant the user could select *any* file and then only find out it's not accepted after uploading.
This ensures the `FileInput` only accepts the listed file extensions _or_ in the absence of file extensions, restricts to audio/video files as appropriate.
@jsma

jsma commented Dec 28, 2025

Copy link
Copy Markdown
Contributor Author

Looks like the Python 3.9 tests failed because of the union operator in type hints. These didn't fail locally for me when running tox. I see #271 is open which would remove Python 3.9 support which is already EOL. Happy to rebase this once that PR is merged.

Comment thread src/wagtailmedia/forms.py
"""Returns the specified extensions in a format usable in the `accept=""` attribute of a `FileInput` widget.
This assumes the list of extensions are the bare extensions e.g., `["mp4", "webm"]` and prefixes each extension with
a ".".
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zerolab zerolab merged commit 5473f09 into torchbox:main Feb 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants