将图像文件发布到在Ionic 3中不起作用的事件 [英] Publishing image file to events not working in Ionic 3
问题描述
我正在Ionic App中工作,并且已经在我的应用程序中进行了更新个人资料图片功能,并且可以正常工作,但是当我尝试更新用户个人资料图片时,它没有发送正确的图片路径.
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.
这是我的 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);
}
}
});
}
});
}
在我的ts文件中,我正在使用以下代码将图像发送到app.html以显示更新的图像:this.events.publish('userprofile:created', this.selectedImage);
,但问题是它没有发送作为文件发送的正确图像URL [对象].
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].
供参考: https://stackblitz.com/edit/ionic-ydphaq
当我将图像发送到about.ts时,它显示了错误.
When I am sending the image to my about.ts, it is showing the error.
非常感谢您的帮助.
推荐答案
您publish
imageUrl 到events
而不是selectedImage.然后,您可以在subscribe
至events
的页面中显示图像.
You publish
imageUrl to events
not the selectedImage. Then you can show image in the pages where subscribe
to events
.
this.events.publish('userprofile:created', this.imageUrl);
这篇关于将图像文件发布到在Ionic 3中不起作用的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!