【发布时间】:2019-10-18 00:51:58
【问题描述】:
我想在 http post 中发送带有名称和描述等表单数据的图像。
var body={
name:name,
description:desc
}
this.http.post("url",body).subscribe(val=>{
console.log(val);
})
如何在 HTTP post 中发送图像和数据?
【问题讨论】:
标签: node.js http ionic-framework
我想在 http post 中发送带有名称和描述等表单数据的图像。
var body={
name:name,
description:desc
}
this.http.post("url",body).subscribe(val=>{
console.log(val);
})
如何在 HTTP post 中发送图像和数据?
【问题讨论】:
标签: node.js http ionic-framework
要以角度发布图像,您需要像这样在表单数据中append它
const formData = new FormData();
formData.append("file", this.angForm.get("image").value);
formData.append("name", this.angForm.get("name").value);
formData.append("description", this.angForm.get("desc").value);
this.http.post("url",formData).subscribe(val=>{
console.log(val);
});
创建一个函数来在改变输入值后检查文件
onFileSelect(event) {
if (event.target.files.length > 0) {
const file = event.target.files[0];
this.form.get("image").setValue(file);
//here form is your form that you use like reactive form
//set form image value
}
【讨论】:
您可以使用FormData 完成此操作
const formData = new FormData()
formData.append('file', imgBlob, filename)
this.http.post('url', formData)
【讨论】: