epergo epergo - 27 days ago 16
Android Question

Cordova camera plugin, obtain full image path from gallery [ANDROID]

I am trying to get an image from the gallery with cordova camera plugin, this is the way I am doing 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 format:

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


And I want the URI with the full path to the image, just like I get it if I use the camera instead:

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


Reading the official documentation I have seen that the only thing I am supposed to do is to set the property 'DestinationType' to 'FILE_URI', which is already set as you can see above.

What am I doing wrong?

Answer

I have found a plugin that converts the URI in 'content://...' format into full file path, it isn't the perfect solution but it is the one has worked for me, the plugin is cordova-plugin-filepath, I use it in the onSuccess callback for the getCamera function:

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