[HttpPost]
public IActionResult Upload(IFormFile image)
{
if (image == null)
{
// 如果用户没有选择图片,则使用默认图片
// 此处假设默认图片的路径为 /default.jpg
var path = Path.Combine(_env.WebRootPath, "default.jpg");
image = new FileStream(path, FileMode.Open);
}
else
{
// 如果用户选择了图片,则保存图片并使用该图片
// 此处将图片保存到 /images 目录下
var filePath = Path.Combine(_env.WebRootPath, "images", image.FileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
image.CopyTo(stream);
}
}
// 处理图片并返回结果
}