public async Task UploadAsync()

in Webapp/SDAF/Controllers/FileController.cs [82:137]


        public async Task<IActionResult> UploadAsync(FileUploadModel fileUpload, string sourceController)
        {
            // Perform an initial check to catch FileUpload class
            // attribute violations.
            if (ModelState.IsValid)
            {
                try
                {
                    string[] permittedExtensions = { ".tfvars" };
                    long fileSizeLimit = 2097152;
                    foreach (var formFile in fileUpload.FormFiles)
                    {
                        byte[] formFileContent =
                            await Helper.ProcessFormFile(formFile, ModelState, permittedExtensions, fileSizeLimit);

                        // Perform a second check to catch ProcessFormFile method
                        // violations. If any validation check fails, return to the
                        // page.
                        if (!ModelState.IsValid)
                        {
                            ViewBag.SourceController = sourceController;
                            return View();
                        }

                        // **WARNING!**
                        // In the following example, the file is saved without
                        // scanning the file's contents. In most production
                        // scenarios, an anti-virus/anti-malware scanner API
                        // is used on the file before making the file available
                        // for download or for use by other systems.
                        // For more information, see the topic that accompanies
                        // this sample.

                        AppFile file = new()
                        {
                            Content = formFileContent,
                            UntrustedName = formFile.FileName,
                            Size = formFile.Length,
                            UploadDT = DateTime.UtcNow,
                            Id = WebUtility.HtmlEncode(formFile.FileName)
                        };

                        await _appFileService.CreateAsync(file);

                        TempData["success"] = "Successfully uploaded file(s)";
                    }
                }
                catch (Exception e)
                {
                    TempData["error"] = "Error uploading files: " + e.Message;
                }
                return RedirectToAction("Index", sourceController);
            }
            ViewBag.SourceController = sourceController;
            return View();
        }