Files
PdfMarker_Web/PdfMarker/Controllers/UploadController.cs
2026-01-23 09:57:52 +01:00

32 lines
834 B
C#

using Microsoft.AspNetCore.Mvc;
namespace PdfMarker.Controllers;
[ApiController]
[Route("api/upload")]
public class UploadController : ControllerBase
{
private readonly IWebHostEnvironment _env;
public UploadController(IWebHostEnvironment env)
{
_env = env;
}
[HttpPost("pdf")]
public async Task<IActionResult> UploadPdf(IFormFile file)
{
if (file == null || file.Length == 0)
return BadRequest("File mancante");
var uploadsPath = Path.Combine(_env.WebRootPath, "uploads");
Directory.CreateDirectory(uploadsPath);
var filePath = Path.Combine(uploadsPath, file.FileName);
await using var stream = new FileStream(filePath, FileMode.Create);
await file.CopyToAsync(stream);
return Ok(new { file = file.FileName });
}
}