[英]Angular 2 file upload to REST API by form-data
When using form-data to upload file with other form inputs, it does not accept the integer. 使用表单数据通过其他表单输入上传文件时,它不接受整数。 When we pass the integer values, it converts as string. 当我们传递整数值时,它将转换为字符串。 But i need to pass integer ie numbers, string and file upload to REST API by form-data. 但是我需要将整数,即数字,字符串和文件通过表单数据传递到REST API。 Can anyone please suggests for this? 有人可以为此建议吗? Thanks in advance. 提前致谢。
Save(model: yourmodalarray[]): Observable<any> {
var formData: FormData = new FormData();
formData.append('id', '');
const headers = new Headers({
'Accept': 'application/json',
'enctype': 'multipart/form-data'
});
const options = new RequestOptions({ headers: headers });
return this._http
.post(this._baseUrl + 'Save', formData, options)
.map(res => <any>res.json())
.catch(this.handleError);
}
Use append method to pass the integer value.i hope this help... 使用append方法传递整数值。希望此帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.