Vas*_*nth 4 cordova hybrid-mobile-app ionic2
我在离子2中创建了一个表单,我有一个字段来上传简历,其类型为.docs或.pdf.我尝试添加如下,
<form [formGroup]="myForm">
<ion-list>
<ion-item>
<input type="file" formControlName="upresume_one" name="upresume_one"/>
<p>Supported formats .doc,.docs and .pdf[Max file size: 500KB]</p>
</ion-item>
<div class="text-right">
<button ion-button style="background-color: #16a085;color: white;" color="secondary" (click)="save(myForm.value)">Submit</button>
</div>
</ion-list>
</form>
Run Code Online (Sandbox Code Playgroud)
我的.ts文件如下:
myForm: FormGroup;
private myData: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private builder: FormBuilder,
private userProfileService: UserProfileService,
private progressDialog: ProgressDialog) {
this.myForm = builder.group({
'upresume_one': ['', Validators.required]
})
Run Code Online (Sandbox Code Playgroud)
提交我正在调用保存功能,如下所示,
save(formData) {
console.log('Form data is ', formData);
}
Run Code Online (Sandbox Code Playgroud)
在consoel.log中,即使选择了有效文件,我也会变为空.有人可以建议我在离子2中将输入类型文件整合到表单中的最佳方法是什么.
Vas*_*nth 12
我终于找到了这个问题的答案.您必须具有可用于上载文件的单独API.以下是在离子2中上传文件的详细步骤:
首先在您的应用程序中安装离子文件选择器插件.https://ionicframework.com/docs/native/file-chooser/
Run Code Online (Sandbox Code Playgroud)this.fileChooser.open() .then(uri => console.log(uri)) .catch(e => console.log(e));
然后从这里将转移插件安装到您的应用程序中:https://ionicframework.com/docs/native/transfer/这可用于将文件上传到您的服务器.
我用来从图库或相机拍照并通过API上传的完整代码如下:https://gist.github.com/coolvasanth/ab61fc337e6561be4559171b74221b1a
要上传.pdf,.docs文件,请参阅:https://gist.github.com/coolvasanth/b266c5bb382ddbfc60ca1c0f7c9f33c0
要从手机捕获视频并通过API将其上传到服务器,请使用以下命令:https://gist.github.com/coolvasanth/8d0b6a4cea480bc7017bce0ba3ec5bdb
要在iOS中选择媒体以外的文件(例如.pdf,.doc),您可以参考以下链接.https://gist.github.com/coolvasanth/d042a26deda75f5e390b42b87995f30d.如果您想从iCloud中选择文件,请在xcode中启用此服务.您可以在Project - > Capabilities - > iTune中找到它.
| 归档时间: |
|
| 查看次数: |
9136 次 |
| 最近记录: |