//public static response RestoreFileFromDb(Models.DocumentScanat ds) public static response RestoreFileFromDb(dynamic ds) { try { if (ds.FILE_CONTENT == null) { ds.GetFileContent(); } if (!File.Exists(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER))) { FileStream fs = new FileStream(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER), FileMode.CreateNew, FileAccess.ReadWrite); fs.Write(ds.FILE_CONTENT, 0, ds.FILE_CONTENT.Length); fs.Flush(); fs.Dispose(); } try { string outputThumbFile = ds.CALE_FISIER.Replace(ds.EXTENSIE_FISIER, "_Custom.jpg"); if (!File.Exists(Path.Combine(CommonFunctions.GetScansFolder(), outputThumbFile))) { ThumbNails.GenerateImgThumbNail(CommonFunctions.GetThumbNailSizes(ThumbNailType.Custom), ds.CALE_FISIER); } } catch (Exception exp) { LogWriter.Log(exp); } return(new response(true, "", null, null, null)); // to do - restore thumbnails }catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new List <Error>() { new Error(exp) })); } }
public static byte[] UploadFile(string filePath, string fileName) { FileStream fs = File.Open(Path.Combine(filePath, fileName), FileMode.Open, FileAccess.Read); byte[] toReturn = new byte[fs.Length]; fs.Read(toReturn, 0, (int)fs.Length); fs.Flush(); fs.Dispose(); response r = ThumbNails.GenerateImgThumbNail(filePath, fileName); return(toReturn); }
/* * public static Dictionary<string, byte[]> UploadFile(ICollection<IFormFile> files) * { * Dictionary<string, byte[]> toReturn = new Dictionary<string, byte[]>(); * * foreach (IFormFile file in files) * { * if (file.Length > 0) * { * toReturn.Add(file.FileName, UploadFile(file)); * } * } * return toReturn; * } */ /* * public static byte[] UploadFile(IFormFile file) * { * BinaryReader reader = new BinaryReader(file.OpenReadStream()); * byte[] toReturn = reader.ReadBytes((int)file.Length); * return toReturn; * } */ public static byte[] UploadFile(string filePath) { string newFilePath = File.Exists(filePath) ? filePath : Path.Combine(CommonFunctions.GetScansFolder(), filePath); FileStream fs = File.Open(newFilePath, FileMode.Open, FileAccess.Read); byte[] toReturn = new byte[fs.Length]; fs.Read(toReturn, 0, (int)fs.Length); fs.Flush(); fs.Dispose(); response r = ThumbNails.GenerateImgThumbNail(filePath); return(toReturn); }
public static string SaveBinaryContentToFile(byte[] fileContent, string extension) { string filePath = Guid.NewGuid() + extension; string newFilePath = File.Exists(filePath) ? filePath : Path.Combine(CommonFunctions.GetScansFolder(), filePath); FileStream fs = File.Create(newFilePath); fs.Write(fileContent, 0, fileContent.Length); fs.Flush(); fs.Dispose(); response r = ThumbNails.GenerateImgThumbNail(filePath); return(filePath); }