I have got the native camera all setup or so I thought…
When trying to navigate to the page to take and upload and image, it’s not directing to the page and also within the console I can see the following error;
Here;s the full code for it.
import { Component, OnInit } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file';
import { HttpClient } from '@angular/common/http';
import { Toast } from '@ionic-native/toast/ngx';
import { Service } from '../../../settings/Laravel';
import { AuthService } from '../../services/auth.Service';
import { LoadingController, NavController } from '@ionic/angular';
@Component({
selector: 'app-property',
templateUrl: './property.page.html',
styleUrls: ['./property.page.scss'],
})
export class PropertyPage implements OnInit {
captureDataUrl: string;
imageURI: any;
user: any;
imageFileName: any;
loading: boolean = false;
constructor(
public camera: Camera,
public http: HttpClient,
private transfer: FileTransfer,
private file: File,
public toast: Toast,
public loadingCtrl: LoadingController,
public navCtrl: NavController,
public auth: AuthService,
)
{ }
ngOnInit() {
}
takePhoto() {
const cameraOptions: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
};
this.camera.getPicture(cameraOptions).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
this.captureDataUrl = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
}
uploadFile() {
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'ionicfile',
fileName: 'ionicfile',
chunkedMode: false,
mimeType: "image/jpeg",
headers: {
authorization: this.auth.user
},
}
fileTransfer.upload(this.captureDataUrl, `${Service.apiUrl}/users/upload/` + this.user.id, options)
.then((data) => {
console.log(data + " Uploaded Successfully");
this.imageFileName = `${Service.apiUrl}` + "/images/ionicfile.jpg"
this.toast.hide();
this.presentToast("Great! We will update your records and notify your Landlord");
this.navCtrl.navigateRoot('/dashboard');
}, (err) => {
console.log(err.data);
this.presentToast('There was an error uploading your file. Please try again!');
});
}
presentToast(msg: string) {
this.toast.show(msg, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
}
}
Any help would be greatly appreciated. Thanks Lee