react-native-rich-editor
react-native-rich-editor copied to clipboard
Cannot display local image resources
It doesn't show up when I've selected an image. it prompts me 'Not allowed to load local resource: file:///Users/xxxxxx/Library/Developer/CoreSimulator/Devices/xxxxxx/data/Containers/Data/Application/xxxxx/tmp/xxx.jpg'. This is my code:
const selectImage = async () => {
try {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
});
if (!result.cancelled) setImageUri(result.base64);
} catch (error) {
console.log("Error reading an image", error);
}
};
let onPressAddImage = useCallback(() => {
selectImage();
// insert URL
richText.current?.insertImage(imageUri);
// insert base64
// this.richText.current?.insertImage(`data:${image.mime};base64,${image.data}`);
}, []);
When I click to add an image, onPressAddImage is called, but the image is not displayed. I have the same problem with this #217 But according to his method I didn't solve the problem. Could you please help me? @rafaelboniolo
I created a correction PR but it still hasn't been accepted, it seems to me the error still persists in production!
Sorry, in production my PR works correctly
I solved this problem temporarily after using base64. Thank you very much
I solved it like
import ImgToBase64 from 'react-native-image-base64';
import ImagePicker from "react-native-image-crop-picker";
openGalleryClickProfile() {
ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true,
}).then((image) => {
console.log("Imagemime", image);
this.onPressAddImage(image)
});
}
onPressAddImage(image){
ImgToBase64.getBase64String(image.path)
.then((base64String) => {
const str = `data:${image.mime};base64,${base64String}`
this.richText.current?.insertImage(
str
);
})
.catch((err) => {
console.log("base64:Image:", err)
})};