public virtual void DeleteTmp(TmpFileData tmp) { if (tmp?.TmpPath != null && File.Exists(tmp.TmpPath)) { File.Delete(tmp.TmpPath); } }
public virtual bool SaveTemp(TmpFileData req, out SavedFileDto dto, long?type = null, string folder = null, bool db = false) { dto = new SavedFileDto(); try { if (req?.TmpPath == null) { return(false); } folder = folder ?? "uploads"; if (type != null && FolderByCategory.TryGetValue(type.Value, out string catFolder)) { folder = catFolder; } string fileName = Utils.GenerateID().ToString() + "_" + req.Name; dto.Path = Utils.CombineUrl(folder, fileName); string saveLocation = Path.Combine(SaveRoot, dto.Path).Replace("/", "\\"); Utils.CreateFolderForFile(saveLocation); FileBytes bytes = null; if (UrlRegex.IsMatch(req.TmpPath)) { bytes = FileUtils.DownloadFile(req.TmpPath); if (bytes != null) { fileName = bytes.FileName; var dir = Path.GetDirectoryName(dto.Path); bytes.Save(dir); } else { return(false); } } else { string cur = Path.Combine(TempRoot, req.TmpPath); if (File.Exists(dto.Path)) { File.Delete(dto.Path); } File.Copy(cur, saveLocation); } return(true); } catch { return(false); } }
public override void DeleteTmp(TmpFileData tmp) { if (tmp.TmpPath != null) { var path = Path.Combine(_paths.TempFolder, tmp.TmpPath); if (File.Exists(path)) { File.Delete(path); } } }
public override bool SaveTemp(TmpFileData req, out SavedFileDto dto, long?type = null, string folder = null, bool db = false) { dto = null; if (req?.TmpPath != null) { var save = req.MapTo <SaveAttachmentRequest>(false); save.AttachmentTypeId = type ?? 0; save.SaveInDb = db; var att = SaveAttachment(save); if (att.IsSuccess && att.Data.TryGetValue("FileData", out object sv)) { dto = (SavedFileDto)sv; return(true); } } return(false); }
public virtual List <TmpFileData> Upload(Dictionary <string, IFormFile> files) { List <TmpFileData> lst = new List <TmpFileData>(); foreach (var d in files) { using (MemoryStream str = new MemoryStream()) { d.Value.CopyTo(str); byte[] byts = str.ToArray(); var bts = new FileBytes(d.Value.FileName, byts); TmpFileData data = FileUtils.AddToTemp(bts, d.Key); if (data != null) { lst.Add(data); } } } return(lst); }
public void LoadFile(IUploadedFilesHandler handl, string serviceUrl = null) { var path = handl.GetUrlByPath(Image); ImageFile = new TmpFileData(path); }
public void LoadFile(IUploadedFilesHandler handl, string serviceUrl = null) { File = new TmpFileData(FileUtils.GetUploadedFileUrl(FilePath)); }