42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Hcs.WebApp.Controllers
|
|
{
|
|
[Authorize]
|
|
[DisableRequestSizeLimit]
|
|
public class UploadController(IWebHostEnvironment webHostEnvironment) : Controller
|
|
{
|
|
private readonly IWebHostEnvironment webHostEnvironment = webHostEnvironment;
|
|
|
|
[HttpPost("upload/parsing")]
|
|
public IActionResult Single(IFormFile file)
|
|
{
|
|
try
|
|
{
|
|
const string directory = "parsing";
|
|
var directoryPath = Path.Combine(webHostEnvironment.WebRootPath, directory);
|
|
if (!Directory.Exists(directoryPath))
|
|
{
|
|
Directory.CreateDirectory(directoryPath);
|
|
}
|
|
|
|
var fileName = $"{DateTime.Today:dd-MM-yyyy}-{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
|
|
var path = Path.Combine(directoryPath, fileName);
|
|
using var stream = new FileStream(path, FileMode.Create);
|
|
file.CopyTo(stream);
|
|
|
|
return Ok(new
|
|
{
|
|
path,
|
|
fileName = file.FileName
|
|
});
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|