From 76b828b46934b36e1b0f4df1329bcbfc5c4676ff Mon Sep 17 00:00:00 2001 From: Frikkie Snyman <10909252+FrikkieSnyman@users.noreply.github.com> Date: Tue, 7 May 2019 21:59:07 +0200 Subject: [PATCH] Use the MimeType reported by the media Cursor instead of trying to guess the mime type from uri (#54) This prevents the crash when the device contains images with a `#` --- .../reactnativecommunity/cameraroll/CameraRollModule.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java index c81f8b12e..8c8ebac73 100644 --- a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java +++ b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java @@ -43,7 +43,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.net.URLConnection; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.List; @@ -366,7 +365,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule { WritableMap edge = new WritableNativeMap(); WritableMap node = new WritableNativeMap(); boolean imageInfoSuccess = - putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex); + putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex, mimeTypeIndex); if (imageInfoSuccess) { putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex); putLocationInfo(media, node, longitudeIndex, latitudeIndex); @@ -401,14 +400,15 @@ public class CameraRollModule extends ReactContextBaseJavaModule { int idIndex, int widthIndex, int heightIndex, - int dataIndex) { + int dataIndex, + int mimeTypeIndex) { WritableMap image = new WritableNativeMap(); Uri photoUri = Uri.parse("file://" + media.getString(dataIndex)); image.putString("uri", photoUri.toString()); float width = media.getInt(widthIndex); float height = media.getInt(heightIndex); - String mimeType = URLConnection.guessContentTypeFromName(photoUri.toString()); + String mimeType = media.getString(mimeTypeIndex); if (mimeType != null && mimeType.startsWith("video")) {