Skip to content

Commit

Permalink
Fix Android Camera Roll crash on mime type guessing (#24780)
Browse files Browse the repository at this point in the history
Summary:
Fixes this issue:
#24468
It was incorrectly closed by a fix on react-native-community CameraRoll implementation. CameraRoll in react-native still crashes when finding a file with # sign

[Android] [Fix] - Fix Android Camera Roll crash on mime type guessing
Pull Request resolved: #24780

Reviewed By: mdvacca

Differential Revision: D15281062

Pulled By: lunaleaps

fbshipit-source-id: ca3364c8478d9bfc9a0a6657b531ffb384145d8c
  • Loading branch information
Sroka authored and facebook-github-bot committed May 10, 2019
1 parent a6f905f commit ebeb893
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import java.net.URLConnection;
import java.net.URL;

// TODO #6015104: rename to something less iOSish
Expand Down Expand Up @@ -388,7 +387,8 @@ private static void putEdges(
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);
Expand Down Expand Up @@ -423,20 +423,15 @@ private static boolean putImageInfo(
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;
try {
mimeType = URLConnection.guessContentTypeFromName(photoUri.toString());
} catch (StringIndexOutOfBoundsException e) {
FLog.e(ReactConstants.TAG, "Unable to guess content type from " + photoUri.toString(), e);
throw e;
}
String mimeType = media.getString(mimeTypeIndex);

if (mimeType != null
&& mimeType.startsWith("video")) {
Expand Down

0 comments on commit ebeb893

Please sign in to comment.