Camera Plugin

Can someone help me understand the ionic-native camera plugin code…

import { Camera, CameraOptions } from '@ionic-native/camera';

constructor(private camera: Camera) { }

...


const options: CameraOptions = {
  quality: 100,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
}

this.camera.getPicture(options).then((imageData) => {
 // imageData is either a base64 encoded string or a file URI
 // If it's base64 (DATA_URL):
 let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
 // Handle error
});

I am currently trying to implement that plugin for the first time, and I am following this post:

https://devdactic.com/ionic-4-image-upload-storage/

Hope it helps.

import { Camera, CameraOptions } from '@ionic-native/camera'; // we import the Camera here

constructor(private camera: Camera) { } // we inject the camera in our class

...

// define some options
const options: CameraOptions = {
  quality: 100, // 100 = full quality (guessed)
  destinationType: this.camera.DestinationType.FILE_URI, // define the type of destination (FILE_URI vs DATA_URL) 
  encodingType: this.camera.EncodingType.JPEG, // set the captured photo as .JPEG
  mediaType: this.camera.MediaType.PICTURE // set the camera mode as picture
}

this.camera.getPicture(options).then((imageData) => { // callback when 
 // IF file_URI so imageData is the captured photo, you can use it here
 // IF base64 (DATA_URL) use this to handle your image
 let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
 // Handle error
});

Hope it helps

what does the line const options: CameraOptions= means? Usually the syntax would be const varName = something…What is CameraOptions here? Some variable?

That’s the typescript’s interface of the object needed. It define the shape of the object.

Agreed…Typescript interface defines on the shape of object…So it totally depends on typescript.