PCRB webassembly

This commit is contained in:
Chase Tucker
2024-05-13 14:33:27 -07:00
parent 9b7e3ef897
commit 89790f4fc1
50 changed files with 5466 additions and 677 deletions

View File

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components.Forms;
using NLog;
namespace MesaFabApproval.API.Utilities;
public class FileUtilities {
private static readonly Logger _logger = NLog.LogManager.GetCurrentClassLogger();
public static async Task SaveFileToFileSystem(IFormFile file, string path) {
try {
_logger.Info($"Attempting to save file to file system");
if (file is null) throw new ArgumentNullException("File cannot be null");
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Path cannot be null or empty");
if (File.Exists(path)) throw new Exception($"A file already exists with name {file.FileName}");
string? directoryPath = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(directoryPath))
Directory.CreateDirectory(directoryPath);
using (Stream stream = File.Create(path)) {
await file.CopyToAsync(stream);
}
} catch (Exception ex) {
_logger.Error($"Unable to save file to file system, because {ex.Message}");
throw;
}
}
}