I've added cordova-plugin-camera plugin to my ionic app, in order to use both of its advantages - take a picture using camera, and get image from the photo gallery.
Taking a picture using camera works perfectly on my android galaxy s3 device, but getting image from gallery returns NULL in the success result function.
I've tried using both $cordovaCamera.getPicture and navigator.camera.getPicture, both returns null as the result param in success method, after i select image on my device.
I've tried playing with all of the params, tried getting any of the 3 options of destinationType (DATA_URL, FILE_URL, NATIVE_URI), tried with saving/unsaving to gallery, edit/unedit, encoding type explicity of jpeg, mediaType PICTURE, etc.. none of them worked with PHOTOLIBRARY or SAVEDPHOTOALBUM, but works fine with CAMERA
This is the code i wrote:
ver 1:
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
allowEdit: true
};
$cordovaCamera.getPicture(options)
.then(function (imageURI) {
if (!imageURI) {
console.log('getPicture: no image selected');
return;
}
// upload image to server code goes here
});
ver 2:
navigator.camera.getPicture(onSuccess, onFail,
{
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
allowEdit: true
});
function onSuccess(imageData) {
console.log(imageData);
// upload image to server code goes here
}
function onFail(message) {
alert('Failed because: ' + message);
}
can anyone advice what could be the problem? (why imageURI/imageData is null) maybe i miss some configuration somewhere? i'm out of ideas..