将文件从react上载到webapi c#
我想上传一个带有一些附加说明的图像,但我不知道如何进一步处理它将文件从react上载到webapi c#,c#,reactjs,webapi,C#,Reactjs,Webapi,我想上传一个带有一些附加说明的图像,但我不知道如何进一步处理它 handleChange = (e) => { var files = e.target.files[0] this.setState({imagesToDB: [...this.state.imagesToDB, files]) } 我的反应组件 submitProperty = (e) => { const { title, location, address, rooms, beds, b
handleChange = (e) => {
var files = e.target.files[0]
this.setState({imagesToDB: [...this.state.imagesToDB, files])
}
我的反应组件
submitProperty = (e) => {
const { title, location, address, rooms, beds, baths, typeProperty, price, description, imagesToDB } = this.state
var form = new FormData();
form.append("title", title)
form.append("location", location)
form.append("address", address)
form.append("rooms", rooms)
form.append("beds", beds)
form.append("baths", baths)
form.append("typeProperty", typeProperty)
form.append("price", price)
form.append("description", description)
form.append("Files", imagesToDB)
e.preventDefault()
fetch("api/advertentie/test", {
method: "POST",
enctype: "multipart/form-data",
body: form
})
Web api控制器
public IHttpActionResult Post()
}
var file = HttpContext.Current.Request.Files;
// file says that it is empty. I see tutorials that I need to for loop
// over the files but it is empty..
var form = HttpContext.Current.Request.Form;
// I receive the form with 10 parameters
var request = HttpContext.Current.Request.Params["Files"];
// the result of requests is "[object File]"
}
我的问题是:如何将
“[对象文件]”
保存到数据库中?通常您需要从请求中获取所有文件,然后分别处理每个文件(获取文件名、内容配置等)。是的,但是计数=0
,所有键
也为0。当我对请求执行foreach
操作时,会得到像9110200这样的字符