diff --git a/android/src/main/java/com/imagepicker/ImagePickerModule.java b/android/src/main/java/com/imagepicker/ImagePickerModule.java index 7fbb798d2..1a9624c9b 100644 --- a/android/src/main/java/com/imagepicker/ImagePickerModule.java +++ b/android/src/main/java/com/imagepicker/ImagePickerModule.java @@ -742,20 +742,26 @@ private String getBase64StringFromFile(String absoluteFilePath) { private void putExtraFileInfo(@NonNull final String path, @NonNull final ResponseHelper responseHelper) { - // size && filename try { + // size && filename File f = new File(path); responseHelper.putDouble("fileSize", f.length()); responseHelper.putString("fileName", f.getName()); + // type + String extension = MimeTypeMap.getFileExtensionFromUrl(path); + String fileName = f.getName(); + if (extension != "") { + responseHelper.putString("type", MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); + } else { + int i = fileName.lastIndexOf('.'); + if (i > 0) { + extension = fileName.substring(i+1); + responseHelper.putString("type", MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); + } + } } catch (Exception e) { e.printStackTrace(); } - - // type - String extension = MimeTypeMap.getFileExtensionFromUrl(path); - if (extension != null) { - responseHelper.putString("type", MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); - } } private void parseOptions(final ReadableMap options) {