From 88bad8c9c626dfddeeb0dc83bb8345a4063d4929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=87=E9=98=B3=20=E9=82=B9?= Date: Fri, 22 Dec 2023 18:52:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=8E=B7=E5=8F=96=E6=89=B9=E9=87=8F=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E7=89=87base=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24Hour/Controllers/Common/CommonController.cs | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/24Hour/Controllers/Common/CommonController.cs b/24Hour/Controllers/Common/CommonController.cs index 46305df..3dda38c 100644 --- a/24Hour/Controllers/Common/CommonController.cs +++ b/24Hour/Controllers/Common/CommonController.cs @@ -2739,6 +2739,8 @@ namespace _24Hour.Controllers.Common #endregion #region 文件上传 + + private string[] AllowedExtensions = new string[] { ".png", ".jpg", ".jpeg", ".bmp", ".zip" ,".xls",".xlsx"}; /// /// 文件上传--附件 /// @@ -2764,8 +2766,8 @@ namespace _24Hour.Controllers.Common var fname = $@"{file.FileName}"; var hzname = $"{Path.GetExtension(fname)}"; - var allowedExtensions = new string[] { ".png", ".jpg", ".jpeg", ".bmp", ".zip" }; - if (allowedExtensions.Contains(hzname.ToLower())==false) + + if (AllowedExtensions.Contains(hzname.ToLower())==false) { outParm.IsSucceed = false; outParm.Message = "不被允许的文件格式!"; @@ -2814,10 +2816,13 @@ namespace _24Hour.Controllers.Common return Json(outParm); }); } + + [HttpGet] [Route("GetImageFile")] public async Task GetImageFile(string file) { + Result result = new Result(); var urlpath = file.Replace("/", @"\"); var path = Path.Combine(Environment.CurrentDirectory, "wwwroot"+urlpath); @@ -2838,6 +2843,43 @@ namespace _24Hour.Controllers.Common return result; } + public class GetBaseStringDto + { + public List Files { get; set; } + } + [HttpPost] + [Route("GetImageFiles")] + public async Task GetImageFiles(GetBaseStringDto file) + { + //根据输入url获取base64值 + var getstr = (string s) => + { + var urlpath = s.Replace("/", @"\"); + var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath); + if (System.IO.File.Exists(path)) + { + return Convert.ToBase64String(System.IO.File.ReadAllBytes(path)); + } + else + { + return ""; + } + }; + //根据输入url获取文件是否存在 + var getexist = (string s) => + { + var urlpath = s.Replace("/", @"\"); + var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath); + return System.IO.File.Exists(s); + }; + var data = file.Files.Select(x => new + { + IsExist = getexist(x), + BaseStr = getstr(x) + }); + result.result = data; + return result; + } /// /// 文件上传--附件 /// @@ -2865,8 +2907,8 @@ namespace _24Hour.Controllers.Common var fname = $@"{file.FileName}"; var hzname = $"{Path.GetExtension(fname)}"; - var allowedExtensions = new string[] { ".png", ".jpg", ".jpeg", ".bmp",".zip" }; - if (allowedExtensions.Contains(hzname.ToLower())==false) + + if (AllowedExtensions.Contains(hzname.ToLower())==false) { outParm.IsSucceed = false; outParm.Message = "不被允许的文件格式!";