react-native-image-editor
react-native-image-editor copied to clipboard
[Android] bug cropImage with base64 URI
Summary
👋 Hi!
When i am using base64 uri with cropImage function it works perfectly with IOS but in Android i have this issue:
[Error: unknown protocol: data]
Environment info
- "react-native": "0.62.2",
- "@react-native-community/image-editor": "^2.3.0",
Reproduce the issue
const base64Uri =
'data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAkACQAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAACQAAAAAQAAAJAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAZCgAwAEAAAAAQAAAZAAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIAZABkAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2wBDAAYGBgYGBgoGBgoOCgoKDhIODg4OEhcSEhISEhccFxcXFxcXHBwcHBwcHBwiIiIiIiInJycnJywsLCwsLCwsLCz/2wBDAQcHBwsKCxMKChMuHxofLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi7/3QAEABn/2gAMAwEAAhEDEQA/APlWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Q+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9H5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//0vlWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//T+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9T5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//1flWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//W+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9f5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//0PlWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//R+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9L5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//0/lWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//U+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9X5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//1vlWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//X+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9D5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//0flWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//S+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9P5VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//1PlWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//V+VaKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9b5VooooAKKKKACu18H+HbTVDcanq7FLCyXdJjI3HGcZHPA5OOeg71xVen2/wDo3wvnaPg3Fz8xH+8o/ktefmVScacYU3ZyaV+1/wDgHdl9OMqjlNXUU3bvYIfEfgq9uRp9zosdvaudonBAkXPAZsAEe/zHHvXKeKvD7eHdWazDF4XAkiY9Sh7H3B4/Wubr0/x1+/0Dw/ev/rHt8Me5yiH+ea51T+q4inGm3yyumm29Urp6m7qfWaFSVRK8bNNJLRu1tCeay8O+CbG2/tWzGo6jcJvZHOEQenII4PHQk4PSrGn2/hnxzbz2lpYrpt/Em9DHjaR07AAjJGeM88GvO9G0ttcvTayXUdvtQtvnbC8EDGfXmvT9P0Z/Bem3GsadnVLqSMxh4QDFEvBJPJY888Dt261w4yEaKt7Rus9ndpb9vhSOzCSlVd/ZpUlvom/87ni7KyMUYYKnBHuK2PD+jTa9qsOmxHaHJ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GwcA9Mqc806uWpynUhUknLs1/kKnmDUYQlCLUfJ/5nrXxGh8OG6nllmmGpiOPZGB+7Iz3+X0z3ryKP76/UVq65rV1r9+dRvFRJCoXEYIXC/Uk/rWQDtII7Vpl2GlQw8ac3d/l5LyM8fiI1q8qkFZf1v5npnxV/5D9v/wBeq/8Aob1g2+jaHJ4Vm1aW+C3yNhYNy+uANv3jkc5HH5Gs3xB4gvfEd4l7fJGjpGIwIgQMAk9y3PNYdRhMJUhhqdJys42vb8i8Viqc8RUqqN09r/menfD9kv7DVvDzMBJdQlo8+uCp/IkGvN5beeG4a1lRllVthQj5g2cYx60+zvLnT7qO8s5DHLEcqw7f/W9RXfD4k3pInksLR7pRgTlDu/nn9amVOvRrTqUY8ylbS9rNafcxxqUa1KFOrLlcb9L3T1LXi1f7H8IaT4el4nJ8+Re6/eJB/wCBOR+FOljbXfhxB9mG+bTJT5ijrtGe3+6wP4GvO9S1O91e8e+v5DJK/foAB0AHYCrmheINS8PXJudPcfMMOjDKOB6j+o5rL+z6kaEeVpzUubybd7r8bGv16nKtK69xrl80ls/wINE0ybWNUt9PhUt5jjdjsmfmJ9gK6r4kX8d74kaKIgi1jWI4/vZLH8t2PwqWb4i34hdNOs7ayklGHljT5vqO355rz53eRzJISzMSSSckk9STW9KlWq11XrR5VFNJXvvuzGrUpU6LoUZXu7t2ttshtFFFekeeFFFFABRRRQAUUUUAf//Z'
ImageEditor.cropImage(base64Uri, {
offset: { x: 0, y: 0 },
size: { width: 100, height: 100 },
})
.then((uri) => { console.log(uri) })
.catch((error) => { console.log(error) })
Is there any update about this issue ?!!
@codifius did you find any solution for this issue?
Fix ImageEditorModule.java
import java.io.ByteArrayInputStream;
import java.util.Base64;
...
private InputStream openBitmapInputStream() throws IOException {
InputStream stream;
if(mUri.startsWith("data:")) {
Base64.Decoder decoder = Base64.getMimeDecoder();
stream = new ByteArrayInputStream(decoder.decode(mUri.substring(mUri.indexOf(",") + 1)));
}
else if (isLocalUri(mUri)) {
stream = mContext.getContentResolver().openInputStream(Uri.parse(mUri));
} else {
URLConnection connection = new URL(mUri).openConnection();
stream = connection.getInputStream();
}
if (stream == null) {
throw new IOException("Cannot open bitmap: " + mUri);
}
return stream;
}
...
then use 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..beca818 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
@@ -13,11 +13,13 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
+import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -243,7 +245,11 @@ public class ImageEditorModule extends ReactContextBaseJavaModule {
private InputStream openBitmapInputStream() throws IOException {
InputStream stream;
- if (isLocalUri(mUri)) {
+ if(mUri.startsWith("data:")) {
+ Base64.Decoder decoder = Base64.getMimeDecoder();
+ stream = new ByteArrayInputStream(decoder.decode(mUri.substring(mUri.indexOf(",") + 1)));
+ }
+ else if (isLocalUri(mUri)) {
stream = mContext.getContentResolver().openInputStream(Uri.parse(mUri));
} else {
URLConnection connection = new URL(mUri).openConnection();
@Hot-key solution worked to me!
Fixed in 3.2.0