Getting pictures from Android gallery weird behavior

Hi, I have been hitting my head against the wall for quite some time trying to solve this issue:

I followed this guide for the basic image select and upload.

Sometimes, though, when selecting a picture from my gallery, nothing happens. Checking the logcat, I found it was raising an exception “Unable to resolve file path”. Ok, weird. If I select another picture, it works. Then If i try to select the one that failed, it now works too.

Added a few more debug logs to my code and I found this out:

The pictures that fail at first, gives me this:

"imagePath /storage/emulated/0/DCIM/Camera/IMG_20191102_114727.jpg" ERROR Error: Uncaught (in promise): Object: {"code":0,"message":"Unable to resolve filesystem path."}

Then the pictures that work, gives me this path:

"imagePath file:///storage/emulated/0/Android/data/com.myapp/cache/IMG_20191106_153214.jpg?1573072706848"

After selecting this second picture, I return to the first one and get the following:

"imagePath file:///storage/emulated/0/Android/data/com.myapp/cache/IMG_20191102_114727.jpg?1573072714092"

Here’s what my camera.getPicture looks like:

   takePicture(sourceType: PictureSourceType) {
        var options: CameraOptions = {
            quality: 100,
            sourceType: sourceType,
            saveToPhotoAlbum: false,
            correctOrientation: true,
            allowEdit: true,
            targetWidth: 300
        }; : string) => {
            if ('android') && sourceType === {
                console.log("imagePath " + imagePath);
                this.filePath.resolveNativePath(imagePath) //this throws the exception
                    .then(filePath => {...}

So… Why the hell some pictures give me a path directly to the camera folder, while some create a copy on my app’s cache before getting selected? And, furthermore, why after opening a picture that creates a copy on cache, all others also do that? Hahahaha

Also, if that is of any use - Considering picture A gives me the camera folder path and picture B gives me the cache path, if I open B first, A works just fine. But if I open A first, it will only work after opening B. I also tried adding file:// to imagePath if it does not start with “file://” but it didn’t work as well.

1 Like