简体   繁体   中英

Cordova Plugin: Unable to retrieve path to picture

Searching for a solution to the following problem for a while and can't seem to find any solutions. Any help is welcome.

The camera plugin of cordova returns the following error when trying to access a picture using the camera.

Unable to retrieve path to picture!

I tried FILE_URI and DATA_URL.

I use cordova version 5.0.0 and cordova-plugin-camera.

The following path fails eg

/storage/emulated/0/Download/horse-331746_640.jpg 

The following path functions eg

/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-2015019-WA0000.JPG 

My Function:

function captureNow(bGallery){

    if(bGallery === true){
        navigator.camera.getPicture(onCapturePhoto, cameraOnFail, {
            quality: 100,
            correctOrientation: 1,
            targetWidth: 500,
            targetHeight: 500,
            encodingType: Camera.EncodingType.JPEG,
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType: Camera.PictureSourceType.PHOTOLIBRARY
        });
    } else {
        navigator.camera.getPicture(onCapturePhoto, cameraOnFail, {
            quality: 100,
            correctOrientation: 1,
            targetWidth: 500,
            targetHeight: 500,
            encodingType: Camera.EncodingType.JPEG,
            destinationType: Camera.DestinationType.FILE_URI
        });
    }
}

The fail message Unable to retrieve path to picture! is caused by hardcoded requirement in the plugin that image selected from gallery must have either image/jpeg or image/png mime type (see cordova-plugin-camera: CameraLauncher.java )

While you are getting this message for JPEG image, I'd say that:

  • even that image has png extension, it's mime type isn't image/jpeg (image is corrupted or it's extension have been renamed)
  • you are using plugin version lower than 4.0.2 which could return this message for other scenarios

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM