public List <dynamic> PersistImage(Microsoft.AspNetCore.Http.IFormFileCollection files) { if (files == null || files.Count == 0) { throw new ApplicationException("no files send to upload"); } List <dynamic> lst = new List <dynamic>(); using (var scope = ServiceActivator.GetScope()) { UploadConfig uplConfig = (UploadConfig)scope.ServiceProvider.GetService(typeof(UploadConfig)); string dirpath = GetDirectory(System.IO.Path.Combine(uplConfig.FullPath, GetCurrentTimeStamp(null))); files.ToList().ForEach(v => { var filepath = GetFile(System.IO.Path.Combine(dirpath, v.FileName)); using (var stream = new System.IO.FileStream(filepath, System.IO.FileMode.Create)) v.CopyTo(stream); lst.Add(new { FileName = System.IO.Path.GetFileName(filepath), DownloadUrl = "" });; }); } return(lst); }
public static void AddArkUpload(this IServiceCollection service, UploadConfig config) { service.AddSingleton <UploadConfig>(config); }