SaeedP
Well-known member
- Joined
- Oct 21, 2020
- Messages
- 116
- Programming Experience
- 3-5
Hello,
This code saves files on wwwroot folder:
How to save Id and name and URL in the model? is it possible for a controller to do these tasks?
regards,
This code saves files on wwwroot folder:
C#:
[Route("WeatherForecast/Post")]
[HttpPost]
public IActionResult Post([FromForm] FileModel file)
{
try
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", file.FileName);
using (Stream stream = new FileStream(path, FileMode.Create))
{
file.FormFile.CopyTo(stream);
}
return StatusCode(StatusCodes.Status201Created);
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
How to save Id and name and URL in the model? is it possible for a controller to do these tasks?
regards,