Загрузить файл отреагировать на webapi c# - PullRequest
2 голосов
/ 02 апреля 2020

Я хочу загрузить изображение с некоторым дополнительным описанием, но я не знаю, как его обработать дальше

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
    })

Контроллер веб-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]"
}

Мой вопрос: как мне сохранить "[object file ]" в моей базе данных?

...