Skip to content

Commit 2d5b7cc

Browse files
Fix DNG/RAW Upload Error (commons-app#5543)
* Fix DNG/RAW Upload Error * Fix DNG/RAW Upload Error * supported formats added * cleanup
1 parent 1cbce77 commit 2d5b7cc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFileLoader.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import kotlinx.coroutines.Dispatchers
1111
import kotlinx.coroutines.launch
1212
import kotlinx.coroutines.withContext
1313
import java.io.File
14-
import java.util.*
14+
import java.util.Calendar
15+
import java.util.Date
16+
import java.util.Locale
1517
import kotlin.coroutines.CoroutineContext
1618

1719
/**
@@ -90,6 +92,12 @@ class ImageFileLoader(val context: Context) : CoroutineScope{
9092
}
9193

9294
if (file != null && file.exists() && name != null && path != null && bucketName != null) {
95+
val extension = path.substringAfterLast(".", "")
96+
// Check if the extension is one of the allowed types
97+
if (extension.lowercase(Locale.ROOT) !in arrayOf("jpg", "jpeg", "png", "svg", "gif", "tiff", "webp", "xcf")) {
98+
continue
99+
}
100+
93101
val uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)
94102

95103
val calendar = Calendar.getInstance()
@@ -130,4 +138,4 @@ class ImageFileLoader(val context: Context) : CoroutineScope{
130138
* Sha1 for image (original image).
131139
*
132140
*/
133-
}
141+
}

app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ private static Intent createGalleryIntent(@NonNull Context context, int type,
4848
boolean openDocumentIntentPreferred) {
4949
// storing picked image type to shared preferences
5050
storeType(context, type);
51+
//Supported types are SVG, PNG and JPEG,GIF, TIFF, WebP, XCF
52+
final String[] mimeTypes = { "image/jpg","image/png","image/jpeg", "image/gif", "image/tiff", "image/webp", "image/xcf", "image/svg+xml", "image/webp"};
5153
return plainGalleryPickerIntent(openDocumentIntentPreferred)
52-
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery());
54+
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery())
55+
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
5356
}
5457

5558
/**
@@ -401,4 +404,4 @@ public interface Callbacks {
401404

402405
void onCanceled(FilePicker.ImageSource source, int type);
403406
}
404-
}
407+
}

0 commit comments

Comments
 (0)