I am working in Ionic App and I have made the update profile image functionality in my app and it is working fine but when I try to update the user profile image it is not sending the image proper path.
This is my updateimage.ts:
onImageSelected(event) {
this.selectedImage = event.target.files[0];
let reader = new FileReader();
reader.onload = (e: any) => {
this.imageUrl = e.target.result;
this.converted_image = "data:image/jpeg;base64,"+this.imageUrl;
};
reader.readAsDataURL(this.selectedImage);
}
changeProfileImage()
{
this.storage.get("ID").then((val) =>
{
if(val)
{
var fd = new FormData();
fd.append('upic', this.selectedImage, this.selectedImage.name);
fd.append('user_id', val);
this.restProvider.updateprofileimg(fd, 'update_profilepic/'+val).subscribe((data) => {
if (data) {
this.responseEdit = data;
if (this.responseEdit.status === 'success') {
this.events.publish('userprofile:created', this.selectedImage); <!-- I am sending the image to the app.html -->
this.presentAlert(this.responseEdit.msg);
}
}
});
}
});
}
In my ts file, I am sending the image to my app.html of showing the updated image using this code: this.events.publish('userprofile:created', this.selectedImage);
but the problem is that it is not sending the proper image URL it is sending as a file[object].
For Reference: https://stackblitz.com/edit/ionic-ydphaq
When I am sending the image to my about.ts, it is showing the error.
Any help is much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…