I am implement native camera feature in Ionic 2, but whenever I run the camera, the error return as below.
Anybody has the same experience? Need the advice on how to fix this issue?
2 429482 group EXCEPTION: Error during evaluation of “click”
4 429485 error ORIGINAL EXCEPTION: TypeError: Cannot read property ‘FILE_URI’ of undefined
3 429483 error EXCEPTION: Error during evaluation of “click”
5 429485 error ORIGINAL STACKTRACE:
6 429486 error TypeError: Cannot read property ‘FILE_URI’ of undefined
My code:
takePhoto() {
var options = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
saveToPhotoAlbum: false,
correctOrientation:true
};
// GitHub - apache/cordova-plugin-camera: Apache Cordova Plugin camera
Camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it’s base64:
this.imgSrc = “data:image/jpeg;base64,” + imageData;
}, (err) => {
});
}
I try to change the code from Camera.DestinationType.FILE_URI
to navigator.camera.DestinationType.FILE_URI
but the console return the error message as below:
error ORIGINAL EXCEPTION: TypeError: Cannot read property ‘DestinationType’ of undefined
First make sure that you have plugin installed. From project directory run: ionic plugin list
and make sure Camera is there. If not run: ionic plugin add cordova-plugin-camera
Here is code that I am using to take a picture and it is working:
let options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
allowEdit: true,
saveToPhotoAlbum: false,
cameraDirection: 1,
sourceType: Camera.PictureSourceType.CAMERA
};
Camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
// this.imgSrc = "data:image/jpeg;base64," + imageData;
this.imgSrc = imageData;
}, (err) => {
});
I tried code below also, but both code still failed to display the picture. <img [src]="imgSrc" id="imgPlacement">
Between, the error message still appear in the console log 757872 error Uncaught TypeError: Cannot read property 'constructor' of null, http://192.168.56.1:8100/build/js/app.bundle.js, Line: 1282