Search code examples
cordovacamerafile-uri

Phonegap FILE_URI, source of image


Got a problem with Phonegap and the camera plugin. I'm trying to display the taken photo in my view, but it doesn't work. I can make it work with DATA_URL, but I need it to work with FILE_URI (because they advice that!)

This is my code, but i guess its not in the code, because with DATA_URL it works, but with the FILE_URI it doesn't, although I have exactly the same code as in the docs.

$('#uploadBusinessCard').on('click', function() {
    console.log("capture this foto!");
    navigator.camera.getPicture(onSuccess, onFail, {
        quality: 10,
        destinationType: Camera.DestinationType.FILE_URI
    });
});

function onSuccess(imageURI) {
    console.log("on success!");
    var image = document.getElementById('myImageIdee');
    image.src = imageURI;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

The code that works is almost the same:

$('#uploadBusinessCard').on('click', function() {
    console.log("capture this foto!");
    navigator.camera.getPicture(onSuccess, onFail, {
        quality: 10,
        destinationType: Camera.DestinationType.DATA_URL
    });
});

function onSuccess(imageData) {
    var image = document.getElementById('myImageIdee');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Solution

  • If you are using the phonegap desktop app and the phonegap developer app on the ipad, there is a knonw issue that doesn't show the images if you use the FILE_URI

    https://github.com/phonegap/phonegap-app-developer/issues/174

    https://github.com/phonegap/phonegap-app-developer/issues/248