I am trying to create a profile photo upload page, I’'m somehow not getting it to work. can some one help?
async openeditprofile() {
let actionSheet = await this.actionsheetCtrl.create({
header : "select an option",
cssClass: "action-sheets-basic-page",
buttons: [
{
text: 'Take photo',
role: 'destructive',
icon: 'Camera',
handler: () => {
this.takephoto();
}
},
{
text: 'Choose photo from Gallery',
icon: 'folder',
handler: () => {
this.send();
// 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.imageData=imageData
this.image=(<any>window).Ionic.WebView.convertFileSrc(imageData);
this.presentToast(this.base64Image);
this.upload();
}, (err) => {
console.log(err);
this.presentToast(err);
})
}
async 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(async (imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.imageData=imageData
this.image=(<any>window).Ionic.WebView.convertFileSrc(imageData);
this.presentToast(this.base64Image);
const loading = await this.loadingController.create({
message: 'Uploading please wait...',
});
await loading.present();
this.upload();
}, (err) => {
console.log(err);
this.presentToast(err);
})}
/////////////////////////////////
async upload()
{
const loading = await this.loadingController.create({
message: 'Uploading...',
});
await loading.present();
const fileTransfer: FileTransferObject = this.transfer.create();
let options1: FileUploadOptions = {
fileKey: 'file',
fileName: 'name.jpg',
headers: {}
}
fileTransfer.upload(this.imageData, 'http://192.168.0.102/io3/upload.php', options1)
.then((data) => {
// success
loading.dismiss()
this.presentToast(data + 'Profile photo uploaded successfully');
}, (err) => {
// error
console.log(err);
loading.dismiss();
this.presentToast(err);
});
}
///////////////////////////////////