2

I need to build a Cordova app which will take a photo, show the photo taken on the app, and upload the photo to the server. Have reference to the following sample code

https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md

To show the photo taken, the following works for me

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
});

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

But when I tried out the following, the photo did not show up.

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.FILE_URI });

function onSuccess(imageURI) {
    var image = document.getElementById('myImage');
    image.src = imageURI;
}

What have I missed? The documentation is wrong?

Thank you in advanced for your help!

H See
  • 21
  • 3
  • For testing, I am using Nexus 4 running KitKat 4.4.4 – H See Dec 27 '14 at 15:07
  • set an alert(imageURI); see what's coming on that `imageURI` – AtanuCSE Dec 27 '14 at 15:46
  • Hi, I did alert (imageURI) while testing. If I use FILE_URI, I get file:///storage/emulated/0/DCIM/Camera/1419742192444.jpg (the jpg filename changed everytime I took a photo of course). When DATA_URL is used, I got a long string /9j/4AA....//Z. – H See Dec 28 '14 at 04:53
  • BTW, I have followed the code given in the first Answer in the following http://stackoverflow.com/questions/26154810/how-to-get-image-object-using-cordova. The cameraImage.src = imageURI; is not working. Have not tried the upload() function though. – H See Dec 28 '14 at 05:47
  • up, also wanting this answer – eeerrrttt May 08 '19 at 15:00

0 Answers0