I have this client code on web-client to load some kind of file.
fileUploaded(files) {
files.forEach(async ifile => {
await axios.post('http://localhost:5000/api/upload', ifile)
.then(res => {
console.log(res)
}).catch(err => {
console.error(err);
});
});
}
My endpoint code looks like this:
[HttpPost("upload")]
public async Task<IActionResult> UploadFile([FromBody] IFormFile file)
{
var data = new byte[file.Length];
using (var bstream = file.OpenReadStream())
{
while (bstream.CanRead)
{
bstream.Read(data);
}
}
// etc
return Ok();
}
Parameter file is always null. How to deliver this file from the client the right way?