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()))
+ }
+ }
}
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 2c0bc3424c..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
@@ -511,10 +511,20 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
receiveInternalSharedItems()
}
- if (uploadableFiles.isEmpty()) {
- handleNullMedia()
- } else {
- //Show thumbnails
+ // 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()
+
+ 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
@@ -700,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)
}
@@ -713,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)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 37b7f8628e..9a1932d89c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -904,4 +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.
+
+ 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.