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