Fix file save process
This commit is contained in:
@ -74,8 +74,8 @@
|
||||
{
|
||||
var root = args.JsonResponse.RootElement;
|
||||
var fileToParse = await FileToParseService.AddFileToParseAsync(
|
||||
root.GetProperty("Path").GetString(),
|
||||
root.GetProperty("FileName").GetString(),
|
||||
root.GetProperty("path").GetString(),
|
||||
root.GetProperty("fileName").GetString(),
|
||||
UploaderId,
|
||||
DateTime.Now);
|
||||
fileToParseId = fileToParse.Id;
|
||||
|
||||
@ -110,15 +110,14 @@ namespace Hcs.WebApp.Components.Shared
|
||||
ShowClose = false
|
||||
});
|
||||
|
||||
var fileToParseId = -1;
|
||||
if (dialogResult != null && int.TryParse(dialogResult, out fileToParseId))
|
||||
if (dialogResult != null)
|
||||
{
|
||||
ChangeState(SyncedPageState.SyncWaiting);
|
||||
|
||||
// TODO: Use user id
|
||||
var campaign = await HeadquartersService.InitiateCampaignAsync(CampaignType, "", new CampaignParseArgs()
|
||||
{
|
||||
FileToParseId = fileToParseId
|
||||
FileToParseId = (int)dialogResult
|
||||
});
|
||||
CampaignManagementState.EnqueueCampaign(campaign);
|
||||
}
|
||||
|
||||
@ -5,23 +5,28 @@ namespace Hcs.WebApp.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[DisableRequestSizeLimit]
|
||||
public class UploadController(IWebHostEnvironment environment) : Controller
|
||||
public class UploadController() : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment environment = environment;
|
||||
|
||||
[HttpPost("upload/parsing")]
|
||||
public IActionResult Single(IFormFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
const string directory = "parsing";
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
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);
|
||||
var path = Path.Combine(directory, fileName);
|
||||
using var stream = new FileStream(path, FileMode.Create);
|
||||
file.CopyTo(stream);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
Path = Url.Content($"~/{fileName}"),
|
||||
FileName = file.FileName
|
||||
path,
|
||||
fileName = file.FileName
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user