From 3b53dd87bd0b61e050e87dd5aaf8186050a61bda Mon Sep 17 00:00:00 2001 From: "hamid.khan@funavry.com" Date: Wed, 27 Sep 2023 11:08:22 +0500 Subject: [PATCH] fixed bug regarding mime type --- .../imageeditor/ImageEditorModule.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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);