epergo epergo - 1 year ago 132
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:


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


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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download