Git Product home page Git Product logo

Comments (19)

chr4ss1 avatar chr4ss1 commented on July 24, 2024 7

I created a patch that fixes the issue, I am not sure why decodeRegion does not give out mime type, but it well could be an issue with the underlying vendor implementation, and am not sure if decodeRegion is guaranteed to fill outMimeType always.

If mime type is null, we fall back to the normal way of reading the mime type, so this patch is quite safe and will affect only people who have problems.

This patch was done for 2.3.0 version for @react-native-community/image-editor, using patch-package.

diff --git a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
index c053ab4..f40883c 100644
--- a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
+++ b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
@@ -255,6 +255,23 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
       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 +289,11 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
 
         String mimeType = outOptions.outMimeType;
         if (mimeType == null || mimeType.isEmpty()) {
-          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);

from react-native-image-editor.

davidwico avatar davidwico commented on July 24, 2024 6

Any update on this?

from react-native-image-editor.

piotrponikowski avatar piotrponikowski commented on July 24, 2024 4

I am also facing this error - are there any plans to solve this one?

from react-native-image-editor.

tommynordli avatar tommynordli commented on July 24, 2024

I'm also seeing this issue, and having several users with the Samsung Galaxy A41 on Android 10 struggling with this.

from react-native-image-editor.

hufkens avatar hufkens commented on July 24, 2024

We also see these errors in our error loggings. Can we expect a fix any time soon?

from react-native-image-editor.

xuananpham93 avatar xuananpham93 commented on July 24, 2024

Any suggestions?

from react-native-image-editor.

pospetur avatar pospetur commented on July 24, 2024

Hoping for a fix soon!

This is happening on the Redmi Note 8 as well, running Android 10.
(https://user-images.githubusercontent.com/2827275/101670290-e17d2c80-3a4a-11eb-9757-02e56ff94322.jpg)

from react-native-image-editor.

blakito avatar blakito commented on July 24, 2024

Also happening with several users using brand new Samsung Core A01, Android 10 (Go Edition)

from react-native-image-editor.

blakito avatar blakito commented on July 24, 2024

Bump. Any updates?

from react-native-image-editor.

chr4ss1 avatar chr4ss1 commented on July 24, 2024

Same error here, affecting A31 Android10

from react-native-image-editor.

blakito avatar blakito commented on July 24, 2024

from react-native-image-editor.

atlkuk avatar atlkuk commented on July 24, 2024

@ChrisEelmaa Did you make a PR for the patch? It can be usefull

from react-native-image-editor.

nes123 avatar nes123 commented on July 24, 2024

Any plans to marge @ChrisEelmaa suggestion? it seems to work well.

from react-native-image-editor.

blakito avatar blakito commented on July 24, 2024

from react-native-image-editor.

ducanh261101a avatar ducanh261101a commented on July 24, 2024

how can i install that patch? i don't know, can you guide me?

I created a patch that fixes the issue, I am not sure why decodeRegion does not give out mime type, but it well could be an issue with the underlying vendor implementation, and am not sure if decodeRegion is guaranteed to fill outMimeType always.

If mime type is null, we fall back to the normal way of reading the mime type, so this patch is quite safe and will affect only people who have problems.

This patch was done for 2.3.0 version for @react-native-community/image-editor, using patch-package.

diff --git a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
index c053ab4..f40883c 100644
--- a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
+++ b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
@@ -255,6 +255,23 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
       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 +289,11 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
 
         String mimeType = outOptions.outMimeType;
         if (mimeType == null || mimeType.isEmpty()) {
-          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);

from react-native-image-editor.

MikePodgorniy avatar MikePodgorniy commented on July 24, 2024

how can i install that patch? i don't know, can you guide me?
@ducanh261101a you can try https://www.npmjs.com/package/patch-package

from react-native-image-editor.

appdeveloperhw avatar appdeveloperhw commented on July 24, 2024

I created a patch that fixes the issue, I am not sure why decodeRegion does not give out mime type, but it well could be an issue with the underlying vendor implementation, and am not sure if decodeRegion is guaranteed to fill outMimeType always.

If mime type is null, we fall back to the normal way of reading the mime type, so this patch is quite safe and will affect only people who have problems.

This patch was done for 2.3.0 version for @react-native-community/image-editor, using patch-package.

diff --git a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
index c053ab4..f40883c 100644
--- a/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
+++ b/node_modules/@react-native-community/image-editor/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModule.java
@@ -255,6 +255,23 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
       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 +289,11 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
 
         String mimeType = outOptions.outMimeType;
         if (mimeType == null || mimeType.isEmpty()) {
-          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);

Thanks it is working

from react-native-image-editor.

bryanltobing avatar bryanltobing commented on July 24, 2024

any update on this issue?

from react-native-image-editor.

retyui avatar retyui commented on July 24, 2024

Fixed in 4.0.0

from react-native-image-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.