Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文件从react上载到webapi c#_C#_Reactjs_Webapi - Fatal编程技术网

将文件从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这样的字符