From d93cda8756fae51b22c17cffd592100b3a66d652 Mon Sep 17 00:00:00 2001 From: Kota-Jagadeesh Date: Thu, 9 Apr 2026 11:58:27 +0530 Subject: [PATCH 1/5] fix: Add string resource for unsupported file type notification --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a89c2e74ad..5dec56de57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -903,4 +903,5 @@ Upload your first media by tapping on the add button. This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, with no conditions. 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. 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. + Some files were skipped: unsupported format. Please use JPEG, PNG, or SVG. From a9449f7d7cee19311544f16cd9b9f0dc9a510897 Mon Sep 17 00:00:00 2001 From: Kota-Jagadeesh Date: Thu, 9 Apr 2026 11:59:05 +0530 Subject: [PATCH 2/5] fix: Add file type validation helper to FileUtils --- .../java/fr/free/nrw/commons/upload/FileUtils.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.kt b/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.kt index 1febd8e884..76db95bb53 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.kt @@ -156,4 +156,20 @@ object FileUtils { } return true } + // list of supported MIME types + private val imageAllowList = listOf( + "image/jpeg", + "image/jpg", + "image/png", + "image/svg+xml" + ) + + fun isSupportedFileType(context: Context, uri: Uri): Boolean { + val mimeType = getMimeType(context, uri) + return if (mimeType == null) { + false + } else { + imageAllowList.contains(mimeType.lowercase(Locale.getDefault())) + } + } } From b7bc35db59f3fea834c0c71807e6adb96e004b5b Mon Sep 17 00:00:00 2001 From: Kota-Jagadeesh Date: Thu, 9 Apr 2026 11:59:30 +0530 Subject: [PATCH 3/5] fix: filter unsupported files in receiveSharedItems --- .../fr/free/nrw/commons/upload/UploadActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt index 97ef10a874..c418c5e6ba 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt @@ -511,6 +511,18 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C receiveInternalSharedItems() } + // Filter the files using the correct property + val originalSize = uploadableFiles.size + uploadableFiles = uploadableFiles.filter { file -> + file.contentUri?.let { uri -> + FileUtils.isSupportedFileType(this, uri) + } ?: false + }.toMutableList() + + // Notify the user if any files were rejected + if (uploadableFiles.size < originalSize) { + showLongToast(this, R.string.unsupported_file_type) + } if (uploadableFiles.isEmpty()) { handleNullMedia() } else { From 955c376431c26ca41be3659a72c608ec39a44bb8 Mon Sep 17 00:00:00 2001 From: Kota-Jagadeesh Date: Sat, 27 Jun 2026 23:29:36 +0530 Subject: [PATCH 4/5] fix: add resources --- app/src/main/res/values/strings.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1dbadbe0bc..9a1932d89c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -904,5 +904,9 @@ Upload your first media by tapping on the add button. This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, with no conditions. 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. 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. - Some files were skipped: unsupported format. Please use JPEG, PNG, or SVG. + + Unsupported Format + The selected files could not be opened. Wikimedia Commons strictly requires JPEG, PNG, or SVG formats. + Unsupported Files Skipped + Some files were skipped due to an unsupported format. The app will continue uploading your remaining JPEG, PNG, or SVG files. From d1c0f01558cf2b917b614cae3d82c8ec87cb71e0 Mon Sep 17 00:00:00 2001 From: Kota-Jagadeesh Date: Sat, 27 Jun 2026 23:32:45 +0530 Subject: [PATCH 5/5] fix: replace unsupported toast type with AlertDialog --- .../free/nrw/commons/upload/UploadActivity.kt | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt index 2a13859875..6732377628 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt @@ -519,14 +519,12 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C } ?: false }.toMutableList() - // Notify the user if any files were rejected - if (uploadableFiles.size < originalSize) { - showLongToast(this, R.string.unsupported_file_type) - } - if (uploadableFiles.isEmpty()) { - handleNullMedia() - } else { - //Show thumbnails + fun proceedWithSetup() { + if (uploadableFiles.isEmpty()) { + handleNullMedia() + return + } + if (uploadableFiles.size > 1) { if (!defaultKvStore.getBoolean("hasAlreadyLaunchedCategoriesDialog")) { // If there is only file, no need to show the image thumbnails @@ -712,7 +710,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C uploadImagesAdapter!!.fragments = fragments!! binding.vpUpload.offscreenPageLimit = fragments!!.size - } + // Saving size of uploadableFiles store!!.putInt(KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE, uploadableFiles.size) } @@ -725,6 +723,35 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C * @param index Index of image to be removed * @param maxSize Max size of the `uploadableFiles` */ + + + if (uploadableFiles.isEmpty() && originalSize > 0) { + showAlertDialog( + this, + getString(R.string.unsupported_format_title), + getString(R.string.unsupported_format_desc), + getString(R.string.ok) + ) { + finish() + } + return + } + + if (uploadableFiles.size < originalSize) { + showAlertDialog( + this, + getString(R.string.unsupported_files_skipped_title), + getString(R.string.unsupported_files_skipped_desc), + getString(R.string.ok) + ) { + proceedWithSetup() + } + return + } + + proceedWithSetup() + } + override fun highlightNextImageOnCancelledImage(index: Int, maxSize: Int) { if (index < maxSize) { binding.vpUpload.setCurrentItem(index + 1, false)