// basic upload, ideally this would be streamed, cleanup temp files and have more error checking public async Task <IActionResult> UploadFile(List <IFormFile> files, string fileType) { // based on MSDN example long size = files.Sum(f => f.Length); var filePath = Path.GetTempFileName(); foreach (var formFile in files) { if (formFile.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } } } string[] fileLines = aspBasicService.ReadFile(filePath); if (aspBasicService.IsFileValid(fileLines, fileType)) { var result = aspBasicService.ImportFile(fileLines, fileType); ViewData["UploadResult"] = result; return(View()); } else { ViewData["UploadResult"] = new ImportResult() { isFatalError = true, errorText = "File is in invalid format" }; return(View()); } }
private void readFileLinesImportResult(string fileNameOnly) { fileLines = aspBasicService.ReadFile("../../../test_files/" + fileNameOnly); // TODO should be a smarter way to find the project dir importResult = aspBasicService.ImportFile(fileLines, FILE_TYPE); }