Here, I can open camera and select image from gallery, but how to upload image to sever PHP, use POST method.
This is my code:
openeditprofile() { let actionSheet = this.actionsheetCtrl.create({ title: 'Option', cssClass: 'action-sheets-basic-page', buttons: [ { text: 'Take photo', role: 'destructive', icon: !this.platform.is('ios') ? 'ios-camera-outline' : null, handler: () => { this.takephoto(); } }, { text: 'Choose photo from Gallery', icon: !this.platform.is('ios') ? 'ios-images-outline' : null, handler: () => { this.openGallery(); } },
] }); actionSheet.present();
}
takephoto() {
> const options: CameraOptions = {
> quality: 100,
> destinationType: this.camera.DestinationType.DATA_URL,
> 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:
> this.base64Image = 'data:image/jpeg;base64,' + imageData;
> this.photos.push(this.base64Image);
> this.photos.reverse();
> }, (err) => {
> // Handle error
> })}
>
> openGallery() {
>
> const options: CameraOptions = {
> quality: 100,
> destinationType: this.camera.DestinationType.DATA_URL,
> encodingType: this.camera.EncodingType.JPEG,
> mediaType: this.camera.MediaType.PICTURE,
> sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM
> }
>
> this.camera.getPicture(options).then((imageData) => {
> // imageData is either a base64 encoded string or a file URI
> // If it's base64:
> this.base64Image = 'data:image/jpeg;base64,' + imageData;
> this.photos.push(this.base64Image);
> this.photos.reverse();
> }, (err) => {
> // Handle error
})}