public ActionResult CompressFile([FromForm] IFormFile file, string name) { try { string file_path = environment.ContentRootPath + $"\\Data\\temporal\\{name}.txt"; string fileName = file.FileName; string file_compressedpath = environment.ContentRootPath + $"\\Data\\compressions\\{name}.lzw"; FileManage _file = new FileManage() { OriginalFileName = file.FileName, CompressedFileName = name + ".lzw", CompressedFilePath = file_compressedpath, DateOfCompression = Convert.ToDateTime(DateTime.Now.ToShortTimeString()) }; //Save the file in the server _file.SaveFile(file, file_path); //Compress the file previously saved _file.CompressFile(file_path); //Write on log file the compression result _file.WriteCompression(_file); //Delete the original file _file.DeleteFile(file_path); FileStream result = new FileStream(_file.CompressedFilePath, FileMode.Open); return(File(result, "text/plain", _file.CompressedFileName)); } catch (Exception) { return(StatusCode(500)); } }
public int CompressFile(FileModel sendFile) { try { string fileName = sendFile.OriginalFileName; string file_path = environment.ContentRootPath + $"\\Data\\temporal\\" + fileName; string file_compressedpath = sendFile.AbsolutePhat; FileManage _file = new FileManage() { OriginalFileName = fileName, CompressedFileName = sendFile.RegisterFileName, CompressedFilePath = file_compressedpath, DateOfCompression = Convert.ToDateTime(DateTime.Now.ToShortTimeString()) }; //Compress the file previously saved _file.CompressFile(file_path, fileName); //Write on log file the compression result _file.WriteCompression(_file); //Delete the original file _file.DeleteFile(file_path); return(1); } catch (Exception) { return(-1); } }