You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
PortfolioLink/backend/Controllers/ExcelUpload.cs

43 lines
1.1 KiB

using Microsoft.AspNetCore.Mvc;
namespace backend.Controllers
{
[Route("api/excelupload")]
[ApiController]
public class ExcelUpload : ControllerBase
{
private readonly IConfiguration _config;
public ExcelUpload(IConfiguration config)
{
_config = config;
}
[HttpPost]
public void ProcessUpload(IFormFile file)
{
// TODO : Add some header validation to make sure it comes from a real user
if (file == null)
{
Console.WriteLine("fail: FILE IS NULL");
return;
}
string dataFileName = Path.GetFileName(file.FileName);
string curDate = DateTime.Now.ToString("u");
string saveToPath = Path.Combine(_config.GetValue<string>("UploadSavePath"), curDate + '_' + dataFileName);
using (FileStream stream = new FileStream(saveToPath, FileMode.Create))
{
file.CopyTo(stream);
Console.WriteLine($"Saved to {saveToPath}.");
}
}
}
}