Код: Выделить всё
public class ChartDTO
{
public string Name { get; set; }
//public byte[] Image { get; set; }
public IFormFile Image { get; set; }
}
Код: Выделить всё
[HttpPost]
[Route("[action]")]
public ActionResult Register([FromForm] ChartDTO dto) // Using IFormFile
{
if (dto.Image.Length > 0)
{
var filePath = Path.Combine("wwwroot\\Charts", dto.Name);
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
try
{
dto.Image.CopyTo(fileStream);
return Ok(new { status = true, message = "Chart posted Successfully" });
}
catch (Exception)
{
return BadRequest();
}
}
}
return BadRequest();
}
Подробнее здесь: https://stackoverflow.com/questions/661 ... ent-to-api
Мобильная версия