Cordova Camera Plugin, from Gallery [Android] Get full image path

I am trying to get images from a gallery with cordova camera plugin, this is how I did it:

navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: Camera.DestinationType.FILE_URI,
mediaType: Camera.MediaType.ALLMEDIA,
encodingType: Camera.EncodingType.JPEG
});

But in my’onSuccess’ function, I get the image URI in the following format:

"content://com.android.providers.media.documents/document/image%3A1509"

I want the URI to have the full path of the image , Like I get it when I use the camera:

"file:///storage/emulated/0/Pictures/IMG_20150710_124222.jpg"

Reading the official documentation I have seen that the only thing I should do is set the attribute’DestinationType’ to’FILE_URI’, which has been set, as shown above.

What am I doing wrong?

I found a plug-in that converts the URI in the format of’content: // …’to complete It’s not a perfect solution, but it’s a plug-in that worked for me. The plug-in is cordova-plugin-filepath. I use it in the onSuccess callback of the getCamera function:

function onSuccess(imageURI) {
window.FilePath.resolveNativePath(imageURI, function(result) {
// onSuccess code
imageURI ='file://' + result;
.. .
}, function (error) {
// onError code here
}
}

I am trying to get images from a gallery with cordova camera plugin, this is how I did it:

navigator.camera.getPicture (onSuccess, onFail, {
quality: 50,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: Camera.DestinationType.FILE_URI,
mediaType: Camera.MediaType.ALLMEDIA,
encodingType: Camera.EncodingType.JPEG
});

But in my’onSuccess’ function, I got the image URI in the following format:

"content://com.android.providers.media.documents/document/image%3A1509"

I want the URI to have the full path of the image, just Like I got it when I used the camera:

"file:///storage/emulated/0/Pictures/IMG_20150710_124222.jpg"

Read I have seen in the official documentation that the only thing I should do is set the attribute’DestinationType’ to’FILE_URI’, which has already been set, as shown above.

What am I doing wrong?

I found a plug-in that converts the URI in the format of’content: // …’into a complete file path. It is not a perfect solution, but It is a plug-in that works for me. The plug-in is cordova-plugin-filepath. I use it in the onSuccess callback of the getCamera function:

function onSuccess(imageURI) {
window.FilePath.resolveNativePath(imageURI, function(result) {
// onSuccess code
imageURI ='file://' + result;
.. .
}, function (error) {
// onError code here
}
}

Leave a Comment

Your email address will not be published.