Implement file upload

This commit is contained in:
2025-11-20 09:55:57 +09:00
parent 7c5c889c53
commit 5b3cb2cabd
9 changed files with 128 additions and 16 deletions

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Hcs.WebApp.Controllers
{
[Authorize]
[DisableRequestSizeLimit]
public class UploadController(IWebHostEnvironment environment) : Controller
{
private readonly IWebHostEnvironment environment = environment;
[HttpPost("upload/parsing")]
public IActionResult Single(IFormFile file)
{
try
{
var fileName = $"{DateTime.Today:dd-MM-yyyy}-{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
using var stream = new FileStream(Path.Combine(environment.WebRootPath, fileName), FileMode.Create);
file.CopyTo(stream);
return Ok(new
{
Path = Url.Content($"~/{fileName}"),
FileName = file.FileName
});
}
catch (Exception e)
{
return StatusCode(500, e.Message);
}
}
}
}