Yehuda
Yehuda

Reputation: 1382

Get picture location - Phonegap camera

I used this code:

function getPicture(){
  navigator.camera.getPicture(onSuccess, onFail, {
    quality: 50,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType : Camera.PictureSourceType.SAVEDPHOTOALBUM
  });
}
function onSuccess(imageURI) {
  img_uri = imageURI;
  alert(img_uri);
  Plugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, 'success', img_uri);
}

I want to get a URI like this: "/mnt/sdcard/Pictures..." but the alert gave me a URI like "content://media/external/images/media/3915".

What can I do?

Upvotes: 7

Views: 4151

Answers (1)

Simon MacDonald
Simon MacDonald

Reputation: 23273

You can use window.resolveLocalFileSystemURI to get the true path. Your onSuccess method would look like:

function onSuccess(imageURI) {
  img_uri = imageURI;
  alert(img_uri);
  window.resolveLocalFileSystemURI(img_uri, function(fileEntry) {
      alert(fileEntry.fullPath);
      Plugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, 'success', fileEntry.fullPath);
  }, onError);      
}

Upvotes: 8

Related Questions