From 2d5b7cc5796825cf02acf0c0f04a786f0ac8b964 Mon Sep 17 00:00:00 2001 From: Shashank Kumar <126143257+shashankiitbhu@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:39:48 +0530 Subject: [PATCH] Fix DNG/RAW Upload Error (#5543) * Fix DNG/RAW Upload Error * Fix DNG/RAW Upload Error * supported formats added * cleanup --- .../customselector/ui/selector/ImageFileLoader.kt | 12 ++++++++++-- .../fr/free/nrw/commons/filepicker/FilePicker.java | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFileLoader.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFileLoader.kt index 88076f19c..bc4d179a2 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFileLoader.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFileLoader.kt @@ -11,7 +11,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File -import java.util.* +import java.util.Calendar +import java.util.Date +import java.util.Locale import kotlin.coroutines.CoroutineContext /** @@ -90,6 +92,12 @@ class ImageFileLoader(val context: Context) : CoroutineScope{ } if (file != null && file.exists() && name != null && path != null && bucketName != null) { + val extension = path.substringAfterLast(".", "") + // Check if the extension is one of the allowed types + if (extension.lowercase(Locale.ROOT) !in arrayOf("jpg", "jpeg", "png", "svg", "gif", "tiff", "webp", "xcf")) { + continue + } + val uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id) val calendar = Calendar.getInstance() @@ -130,4 +138,4 @@ class ImageFileLoader(val context: Context) : CoroutineScope{ * Sha1 for image (original image). * */ -} \ No newline at end of file +} diff --git a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java index 201aacb86..08453a95d 100644 --- a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java +++ b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java @@ -48,8 +48,11 @@ public class FilePicker implements Constants { boolean openDocumentIntentPreferred) { // storing picked image type to shared preferences storeType(context, type); + //Supported types are SVG, PNG and JPEG,GIF, TIFF, WebP, XCF + final String[] mimeTypes = { "image/jpg","image/png","image/jpeg", "image/gif", "image/tiff", "image/webp", "image/xcf", "image/svg+xml", "image/webp"}; return plainGalleryPickerIntent(openDocumentIntentPreferred) - .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery()); + .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery()) + .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); } /** @@ -401,4 +404,4 @@ public class FilePicker implements Constants { void onCanceled(FilePicker.ImageSource source, int type); } -} \ No newline at end of file +}