Skip to content

Implement file type validation to prevent unsupported uploads#6825

Open
Kota-Jagadeesh wants to merge 11 commits into
commons-app:mainfrom
Kota-Jagadeesh:fix/filter-unsupported-uploads
Open

Implement file type validation to prevent unsupported uploads#6825
Kota-Jagadeesh wants to merge 11 commits into
commons-app:mainfrom
Kota-Jagadeesh:fix/filter-unsupported-uploads

Conversation

@Kota-Jagadeesh

Copy link
Copy Markdown
Collaborator

Description (required)

Fixes #6651

Currently, the app allows users to select or share unsupported file types (like GIFs or WebP) through external intents, only to fail at the final upload stage. This PR implements a validation layer to ensure only the recommended formats are processed.

Changes made:

  • FileUtils.kt: Introduced isSupportedFileType utility and an imageAllowList containin supported MIME types (image/jpeg, image/png, image/svg+xml).
  • UploadActivity.kt: Integrated the filtering mechanism in receiveSharedItems that validates files before they enter the upload.
  • strings.xml: Added a toast notification to provide immediate feedback when a file is skipped due to its format.

Tests performed (required)

Tested ProdDebug on Redmi Note 13 Pro with API level 36.

  • Verified that supported format files are accepted and proceed to the upload screen normally.
  • Verified that sharing a GIF or WebP file from an external gallery triggers the "Unsupported format" toast and prevents the upload from opening.
  • also verified that if a mix of supported and unsupported files are shared, the app correctly filters the list and proceeds with only the valid items.

Screenshots (for UI changes only)

@Kota-Jagadeesh

Copy link
Copy Markdown
Collaborator Author

tested the app with a mix of supported and unsupported files. verified that it successfully skipped the unsupported files and displayed a toast notification to inform the user

Screenrecorder-2026-04-09-12-21-59-342.mp4

@Kota-Jagadeesh

Copy link
Copy Markdown
Collaborator Author

shared the same folder from the external gallery app :

Screenrecorder-2026-04-09-12-26-58-883.mp4

@nicolas-raoul

Copy link
Copy Markdown
Member

Testing this PR with .heic:

0aea1b30-b9c4-495e-a422-6a73496616c0.mp4
  • I believe a toast is not the recommended way to show such information nowadays, right? Maybe a snack?
  • The message is cropped, make it shorter if needed.
  • I also see Error occurred while processing the image. Please ..., is this intended?

Screenshot_20260605-170001.png

@Kota-Jagadeesh

Copy link
Copy Markdown
Collaborator Author

@nicolas-raoul Thanks for testing. I have updated the PR with the suggestions above, please check it and lmk about the changes when you have time :)

@github-actions

Copy link
Copy Markdown

✅ Generated APK variants!

@nicolas-raoul nicolas-raoul left a comment

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.

I have been using this branch for several weeks, it is working great and the other features still work as before.

handleNullMedia()
} else {
//Show thumbnails
// Filter the files using the correct property

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.

Can you make that comment more understandable to someone who is not familiar with the context?

<string name="license_cc_by_sa_long_description">This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, even for commercial purposes, as long as attribution is given to the creator and the new work is licensed under identical terms.</string>

<string name="unsupported_format_title">Unsupported Format</string>
<string name="unsupported_format_desc">The selected files could not be opened. Wikimedia Commons strictly requires JPEG, PNG, or SVG formats.</string>

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.

Problem: When we add a new supported format, this will need to be re-localized in dozens of languages.

Is there any way to store "JPEG", "PNG", "SVG" as a list, and have the app use this list?

Please note that , is not universal (for instance Japan uses instead) so either find a localization method that allows this, or display each format on a new line after the explanation.

This list should be used by unsupported_files_skipped_desc too.

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.

Only accept actually supported filetypes

2 participants