public IActionResult Show(string id, bool isTurn = false) { var fileId = Guid.Empty; if (!Guid.TryParse(id, out fileId)) { return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode("fileId not found , server refused !"))); } var fileModel = _abpFilerepository.Get(fileId); if (isTurn) { fileModel = _abpFilerepository.FirstOrDefault(x => x.TurnType == TurnType.转PDF && x.TurnFileId == fileId); } var filepath = fileModel.FilePath; var fileName = fileModel.FileName; FileInfo tmpFile = new FileInfo(filepath); if (!tmpFile.Exists) { var message = "文件不存在"; return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode(message))); } var stream = System.IO.File.OpenRead(tmpFile.FullName); return(File(stream, "application/vnd.android.package-archive", Path.GetFileName(fileName))); }
//[Route("accountantCoursePost")] public IActionResult AccountantCoursePost() { var files = Request.Form.Files; long size = files.Sum(f => f.Length); //size > 100MB refuse upload ! if (size > 104857600) { return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode("file total size > 500MB , server refused !"))); } var filePathResultList = new List <TempAbpFileUploadResultModel>(); foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"'); var old_fileName = fileName; string filePath = hostingEnv.WebRootPath + $@"/Files/upload/temp/"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string suffix = fileName.ToString().Split(".")[1]; //if (!pictureFormatArray.Contains(suffix)) //{ // return Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode("the picture format not support ! you must upload files that suffix like 'png','jpg','jpeg','bmp','gif','ico'.")); //} fileName = Guid.NewGuid() + "." + suffix; string fileFullName = filePath + fileName; using (FileStream fs = System.IO.File.Create(fileFullName)) { file.CopyTo(fs); fs.Flush(); } var ret = new TempAbpFileUploadResultModel() { Id = Guid.NewGuid(), FileName = old_fileName, Size = file.Length, FileExtend = suffix, FileRelationPath = fileName, }; filePathResultList.Add(ret); } string message = $"{files.Count} file(s) /{size} bytes uploaded successfully!"; return(Json(AbpFileReturn_Helper_DG.Success_Msg_Data_DCount_HttpCode(message, filePathResultList, filePathResultList.Count))); }
public IActionResult ShowFile(string filename) { string filePath = hostingEnv.WebRootPath + $@"/Files/upload/" + filename + ".xlsx"; FileInfo tmpFile = new FileInfo(filePath); if (!tmpFile.Exists) { var message = "文件不存在"; return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode(message))); } var stream = System.IO.File.OpenRead(tmpFile.FullName); return(File(stream, "application/vnd.android.package-archive", Path.GetFileName(filename + "工作日报.xlsx"))); }
public IActionResult GetInfo(string id) { var fileId = Guid.Empty; if (!Guid.TryParse(id, out fileId)) { return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode("fileId not found , server refused !"))); } var fileModel = _abpFilerepository.Get(fileId); FileInfo tmpFile = new FileInfo(fileModel.FilePath); if (!tmpFile.Exists) { var message = "文件不存在"; return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode(message))); } return(Json(fileModel)); }
public IActionResult Post(bool isWordToPdf = false) { var files = Request.Form.Files; long size = files.Sum(f => f.Length); var coreAssemblyDirectoryPath = typeof(AbpFileController).GetAssembly().GetDirectoryPathOrNull(); var _appConfiguration = AppConfigurations.Get(coreAssemblyDirectoryPath); var bodySize = Convert.ToInt32(_appConfiguration["App:MaxRequestBodySize"]); //size > 100MB refuse upload ! if (size > (bodySize * 1024 * 1024)) { //throw new UserFriendlyException((int)ErrorCode.DataAccessErr, $"上传文件大于{bodySize}MB ,请联系管理员。"); return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode($"上传文件大于{bodySize}MB ,请联系管理员。"))); } var filePathResultList = new List <AbpFileUploadResultModel>(); foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"'); var old_fileName = fileName; var dt = DateTime.Now; string filePath = hostingEnv.WebRootPath + $@"/Files/upload/" + dt.Year + "/" + dt.Month + "/"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string suffix = fileName.ToString().Split(".")[1]; //if (!pictureFormatArray.Contains(suffix)) //{ // return Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode("the picture format not support ! you must upload files that suffix like 'png','jpg','jpeg','bmp','gif','ico'.")); //} fileName = Guid.NewGuid() + "." + suffix; string fileFullName = filePath + fileName; using (FileStream fs = System.IO.File.Create(fileFullName)) { file.CopyTo(fs); fs.Flush(); } var ret = new AbpFileUploadResultModel() { Id = Guid.NewGuid(), FileName = old_fileName, Size = file.Length, FileExtend = suffix, }; filePathResultList.Add(ret); var entity = new AbpFile() { Id = ret.Id, FileName = ret.FileName, FileExtend = ret.FileExtend, FileSize = ret.Size, FilePath = fileFullName }; _abpFilerepository.Insert(entity); if (isWordToPdf) { var ext = suffix.ToLower(); if (ext == "doc" || ext == "docx") { var savePath = fileFullName.Replace("." + suffix, ".pdf"); try { ThreePartDll.ThreePartDllHelper.CreatePDF(fileFullName, savePath); var turnFilePath = savePath; var turnFileName = old_fileName.Replace("." + suffix, ".pdf"); System.IO.FileInfo objFI = new System.IO.FileInfo(savePath); entity = new AbpFile() { Id = Guid.NewGuid(), FileName = turnFileName, FileExtend = "pdf", FileSize = objFI.Length, TurnFileId = ret.Id, TurnType = TurnType.转PDF, FilePath = turnFilePath }; _abpFilerepository.Insert(entity); } catch (Exception ex) { return(Json(AbpFileReturn_Helper_DG.Error_Msg_Ecode_Elevel_HttpCode($"转档失败"))); } } } /* //文件转为文本存入elasticsearch * var pageoffice = new Search(); * pageoffice.Id = entity.Id; * pageoffice.Content = entity.FilePath; * pageoffice.Title = entity.FileName; * _searchAllAppService.CreateOffice(pageoffice);*/ } string message = $"{files.Count} file(s) /{size} bytes uploaded successfully!"; return(Json(AbpFileReturn_Helper_DG.Success_Msg_Data_DCount_HttpCode(message, filePathResultList, filePathResultList.Count))); }