我正在开发离子3移动应用程序,我想将图像从移动应用程序上传到Web API。为此,我使用Post方法发送图像。我正在尝试将映像作为多部分文件上载,因为服务器需要多部分文件。因此,我添加了一个输入字段来选择文件,如。接下来,我创建了
changeListener()
事件将图像发送到服务器。
<ion-input type="file" accept="image/*" id="upload" [(ngModel)]="imagePath" (ionChange)="changeListener($event)"></ion-input>
changeListener($event): void {
this.imagePath = $event.target.files[0];
console.log($event.target.files[0])
this.imageProvider.uploadImage(this.imagePath)
}
当我选择文件时,它会给我一个类型错误,比如“无法读取未定义的属性文件”。
有人能帮忙解决这个问题吗?