Hello i was wondering how could you send both a POCO and files within a form.
My problem is twofold:
- 1.So far when i acess the
Request.Form.Files[0]and copy it in a file i get a0kbfile. - If i want to get the
MyPocoobject from my form when i use the[FromBody]as a parameter to my method i get a415not supported type.
Form
<form id="createForm" method="post" enctype="multipart/form-data" action="http://localhost:8300/api/create">
<input type="text" bind="@model.Name"/>//some binding here
<input type="text" bind="@model.Id"/> //some binding...
<input type="file"/>
</form>
Controller
[HttpPost]
[Route("api/create")]
public async Task<long> CreateAsync([FromBody] MyPoco poco) { //getting error 415 when using the FromBody
try {
MyPoco poc = poco;
string path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"file.csv"); //copy the input file -> getting 0kb file
FileStream stream = new FileStream(path, FileMode.Create);
await this.Request.Form.Files[0].CopyToAsync(stream);
return 3;
} catch (Exception) {
return 0;
}
}
P.S The syntax of binding is blazor but it is unimportant in this case.
