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 `#`
This commit is contained in:
Frikkie Snyman 2019-05-07 21:59:07 +02:00 committed by Bartol Karuza
parent f5973f8ebe
commit 76b828b469
1 changed files with 4 additions and 4 deletions

View File

@ -43,7 +43,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -366,7 +365,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
WritableMap edge = new WritableNativeMap(); WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap(); WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess = boolean imageInfoSuccess =
putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex); putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex, mimeTypeIndex);
if (imageInfoSuccess) { if (imageInfoSuccess) {
putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex); putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(media, node, longitudeIndex, latitudeIndex); putLocationInfo(media, node, longitudeIndex, latitudeIndex);
@ -401,14 +400,15 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
int idIndex, int idIndex,
int widthIndex, int widthIndex,
int heightIndex, int heightIndex,
int dataIndex) { int dataIndex,
int mimeTypeIndex) {
WritableMap image = new WritableNativeMap(); WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.parse("file://" + media.getString(dataIndex)); Uri photoUri = Uri.parse("file://" + media.getString(dataIndex));
image.putString("uri", photoUri.toString()); image.putString("uri", photoUri.toString());
float width = media.getInt(widthIndex); float width = media.getInt(widthIndex);
float height = media.getInt(heightIndex); float height = media.getInt(heightIndex);
String mimeType = URLConnection.guessContentTypeFromName(photoUri.toString()); String mimeType = media.getString(mimeTypeIndex);
if (mimeType != null if (mimeType != null
&& mimeType.startsWith("video")) { && mimeType.startsWith("video")) {