34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|