Reputation: 151
I am trying to send a file and other data to an Asp-Core-BackEnd.
In the backendController, I read the file like:
IFormFile file = HttpContext.Request.Form.Files.First(); //don't work
HttpContext.Request.Form.TryGetValue("id", out id) //works
Works for other Clients. But I want use the Api with JS.
My js-code (react) looks like this:
const formData = new FormData();
formData.append('id', 123);
formData.append('files', files); //don't work
const config = {
headers: {
'content-type': 'multipart/form-data; charset=utf-8; boundary="------";'
}
}
await axios.post(url, formData, config);
but Form.Files is an empty Array
Upvotes: 1
Views: 4326
Reputation: 15916
Try this?
[HttpPost]
public string getfile([FromForm] string id, [FromForm] IFormFile file) {
return "success";
}
Upvotes: 3