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?
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
}
}
You can also do it using single button with the help of confirm box:
var txt=confirm("Select photo source");
if(txt==true){
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,destinationType: Camera.DestinationType.DATA_URL,saveToPhotoAlbum: true,sourceType: Camera.PictureSourceType.CAMERA});
}
else{
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,destinationType: Camera.DestinationType.DATA_URL,saveToPhotoAlbum: true,sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
}
If ok,then camera opens else if you click cancel, then galery opens
you can also customize ok-cancel button of confirm botton according to your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With