React-native-image-crop-picker: ENOENT: no such file or directory open

Created on 23 Mar 2017  路  6Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.11.2
  • react-native v0.36

Platform

Tell us to which platform this issue is related

  • Android 6.0

Actual behaviour

Possible unhanbdled Promise Rejection (id:1)
ENOENT: no such file or directory open file:///storage/emulated/0/Pictures/....

I have this code

ImagePicker.openCamera({
                                width: 300,
                                height: 400,
                                includeBase64: true,
                                compressImageMaxWidth: 1920,
                                compressImageMaxHeight: 1200,
                                compressImageQuality: 0.5
                            }).then(image => {
                                this.saveImages([image]);

                                this.refs.subMenu.setModalVisible(false);
                            }).catch((e) => {
                                console.log(e)
                            });

And it works as expected on iOS, but on android I run in the above exception.

I tried upgrading to 0.12.8 since I saw that you have a fix for similar issue:
https://github.com/ivpusic/react-native-image-crop-picker/commit/a892a7e432477fb471a61b868522d8391a40c6bd

But it didn't help. Right now I downgraded to 0.11.2 (as I can't use 0.12.8 on ios) and applied the above patch to the code, but still I can't attach an image.

Any ideas how to debug this?

All 6 comments

Well, I'm currently not sure if it is the imagepicker.
Image picker returns an image obejct with this path in it: storage/emulated/0/Pictures/...
And after that I'm trying to move the file to the final position with RNFS and this is where I get the error that the file is not existing. I'm looking at the device with Android Device Monitor and there isn't a 0/Picutres folder in storage/emulated. But i'm wondering why isn't the ImageCroper complaining about that? I have the correct base64, but the image is not in a file on the device.

@ivpusic - so, everything is OK with the library. But maybe the following information would be of use.

The problem turned out to be RNFS on Android in combination with RN image crop picker.

On Android you are returning an image object that contains a path. The path is formated with file:///storage....

it turns out that RNFS can't find files with that path. I had to strip the file:// from the path to make it work.
So far I understood from researching this issue - file:// is used in URI schemes and if we are talking about local files, then we should use /...
Should the image.path property be file:// or / on Android? on Ios the image path starts with /...

I had the same problem and solved it for my use case by first checking if the directory exists, and if not, create it.

e.g. in createImageFile of PickerModule.java add

if(!path.exists()) {
    path.mkdirs();
 }

so that the whole function looks like

String imageFileName = "image-" + UUID.randomUUID().toString();
        File path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        if(!path.exists()) {
            path.mkdirs();
        }
        File image = File.createTempFile(imageFileName, ".jpg", path);

        // Save a file: path for use with ACTION_VIEW intents
        mCurrentPhotoPath = "file:" + image.getAbsolutePath();

        return image;
}

@kiranlak This behavior described by you was recently fixed in #292. Release 0.12.10 already implements it.

@andrevargas Yes, I saw a few minutes ago when I updated 馃槅

Was this page helpful?
0 / 5 - 0 ratings