【发布时间】:2017-06-15 06:20:03
【问题描述】:
您好,我想上传多个文件并将它们发送到服务器:使用反应形式: 我在适当的类中定义它:
this.attachmentsForm = this.formBuilder.group({
attachmentName: ['']
});
在模板 html 中:
<form [formGroup]="attachmentsForm">
<ion-item>
<ion-label floating>
Attachment Name
</ion-label>
<ion-input type="text" formControlName="attachmentName"></ion-input>
</ion-item>
<input class="form-control" #fileInput type='file' (change)="fileChanged($event)">
</form>
在这个课程中我使用了这个功能:
fileChanged(event) {
if (event.target.files && event.target.files[0]) {
if (event.target.files[0].size > 512000) {
this.fileValid = false;
let toast = this.toastCtrl.create({
message: 'the file size more than 500kb',
duration: 3000
});
toast.present();
} else {
this.fileValid = true;
}
}
}
那么我怎样才能获得附件的数据:(Base64 或者如果有其他解决方案) 提前致谢
【问题讨论】:
标签: javascript angular ionic2 ionic3