using _0_Framework.Application; namespace BackgroundInstitutionContract.Task { public class FileUploader : IFileUploader { private readonly IWebHostEnvironment _webHostEnvironment; public FileUploader(IWebHostEnvironment webHostEnvironment) { _webHostEnvironment = webHostEnvironment; } public string Upload(IFormFile file, string path) { if (file == null) return ""; var directoryPath = $"{_webHostEnvironment.WebRootPath}\\ProductPictures\\{path}"; if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath); var fileName = $"{DateTime.Now.ToFileName()}-{file.FileName}"; var filePath = $"{directoryPath}\\{fileName}"; var output = System.IO.File.Create(filePath); file.CopyTo(output); return $"{path}/{fileName}"; } } }