diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java index c053ab4..4346824 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java @@ -255,6 +255,20 @@ private InputStream openBitmapInputStream() throws IOException { return stream; } + private String getMimeType() throws IOException { + + BitmapFactory.Options outOptions = new BitmapFactory.Options(); + outOptions.inJustDecodeBounds = true; + InputStream inputStream = openBitmapInputStream(); + try { + BitmapFactory.decodeStream(inputStream, null, outOptions); + return outOptions.outMimeType; } finally { + if (inputStream != null) { + inputStream.close(); + } + } + } + @Override protected void doInBackgroundGuarded(Void... params) { try { @@ -272,7 +286,13 @@ protected void doInBackgroundGuarded(Void... params) { String mimeType = outOptions.outMimeType; if (mimeType == null || mimeType.isEmpty()) { - throw new IOException("Could not determine MIME type"); + // throw new IOException("Could not determine MIME type"); + + mimeType = getMimeType(); + + if (mimeType == null || mimeType.isEmpty()) { + throw new IOException("Could not determine MIME type"); + } } File tempFile = createTempFile(mContext, mimeType);