uploadImg(img: HTMLInputElement, code: any): void {
if (this.imgs.length > 5) {
alert("最多只能上传6张图片");
return;
}
console.info(img.files[0]);
let form = new FormData();
form.append("img", img.files[0],img.files[0].name);
// let newForm = new FormData(form[0]);
this.commodityService.uploadImg(form, code)
.then(data => {
// this.imgurl = data.url;
this.imgs.push(data.url);
});
}
uploadImg(params: any,code:any): Promise<any> {
return this.http.post("http://localhost:3000/bsp/bsp/bspmddata/item/addItemFiles?code="+code, params,{withCredentials: true})
.toPromise()
.then(
res => {
return Promise.resolve(res.json() as any)
}
)
.catch(this.handleError);
}