From 180dfb0a37f2dbd011d6efaec1198940627e58e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=87=E9=98=B3=20=E9=82=B9?= Date: Sat, 23 Dec 2023 11:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=92=8C?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=97=B6=E8=BF=9B=E8=A1=8C=E5=8A=A0=E8=A7=A3?= =?UTF-8?q?=E5=AF=86=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24Hour/Controllers/Common/CommonController.cs | 86 ++----------------- 1 file changed, 9 insertions(+), 77 deletions(-) diff --git a/24Hour/Controllers/Common/CommonController.cs b/24Hour/Controllers/Common/CommonController.cs index b7a5713..22a9544 100644 --- a/24Hour/Controllers/Common/CommonController.cs +++ b/24Hour/Controllers/Common/CommonController.cs @@ -2767,7 +2767,7 @@ namespace _24Hour.Controllers.Common var hzname = $"{Path.GetExtension(fname)}"; - if (AllowedExtensions.Contains(hzname.ToLower())==false) + if (AllowedExtensions.Contains(hzname.ToLower()) == false) { outParm.IsSucceed = false; outParm.Message = "不被允许的文件格式!"; @@ -2775,6 +2775,7 @@ namespace _24Hour.Controllers.Common } + var _path = Path.Combine("CaseFile", "card", DateTime.Now.ToString("yyyy-MM-dd")); var dic = Path.Combine(Environment.CurrentDirectory, "wwwroot", _path); @@ -2786,16 +2787,14 @@ namespace _24Hour.Controllers.Common var __path = Path.Combine(_path, filename); path = System.IO.Path.ChangeExtension(path, "aks"); - using (var stream = new FileStream(path, FileMode.OpenOrCreate)) + using (var ms = new MemoryStream()) { - await file.CopyToAsync(stream); + await file.CopyToAsync(ms); + var Encryptiondata = Elight.Utility.Encrypt.DataEncryption.Encryption(ms.ToArray()); + await System.IO.File.WriteAllBytesAsync(path, Encryptiondata); } - // var __path = $"{_path}/{filename}"; - __path = System.IO.Path.ChangeExtension(__path, "aks"); - - var repath = "/" + __path.Replace(@"\", @"/"); outParm.IsSucceed = true; outParm.result = new @@ -2828,7 +2827,7 @@ namespace _24Hour.Controllers.Common var path = Path.Combine(Environment.CurrentDirectory, "wwwroot"+urlpath); if (System.IO.File.Exists(path)) { - var str = Convert.ToBase64String(System.IO.File.ReadAllBytes(path)); + var str = Elight.Utility.Encrypt.DataEncryption.Decryptiones(path); result.result = new { BaseStr = str @@ -2856,7 +2855,7 @@ namespace _24Hour.Controllers.Common var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath); if (System.IO.File.Exists(path)) { - return Convert.ToBase64String(System.IO.File.ReadAllBytes(path)); + return Elight.Utility.Encrypt.DataEncryption.Decryptiones(path); } else { @@ -2898,74 +2897,7 @@ namespace _24Hour.Controllers.Common public async Task Upload_Files1(IFormFile file) { - Result outParm = new Result(); - return await Task.Run(async () => - { - if (file.Length <= 0) - { - outParm.IsSucceed = false; - outParm.Message = "请上传文件!"; - return Json(outParm); - } - try - { - var size = Request.Form.Files.Sum(f => f.Length); - IFormFile file = Request.Form.Files.FirstOrDefault(); - var fname = $@"{file.FileName}"; - var hzname = $"{Path.GetExtension(fname)}"; - - - if (AllowedExtensions.Contains(hzname.ToLower())==false) - { - outParm.IsSucceed = false; - outParm.Message = "不被允许的文件格式!"; - return Json(outParm); - } - - - - var _path = Path.Combine("CaseFile", "card", DateTime.Now.ToString("yyyy-MM-dd")); - var dic = Path.Combine(Environment.CurrentDirectory, "wwwroot", _path); - - if (!System.IO.Directory.Exists(dic)) - Directory.CreateDirectory(dic); - var filename = $"{DateTime.Now:yyyyMMddHHmmssfff}{Path.GetExtension(fname)}"; - var filepath = Path.Combine(_path, $"{filename}"); - var path = Path.Combine(dic, $"{filename}"); - var __path = Path.Combine(_path, filename); - path = System.IO.Path.ChangeExtension(path, "aks"); - - using (var stream = new FileStream(path, FileMode.OpenOrCreate)) - { - await file.CopyToAsync(stream); - } - // var __path = $"{_path}/{filename}"; - - - __path = System.IO.Path.ChangeExtension(__path, "aks"); - - - var repath = "/" + __path.Replace(@"\", @"/"); - - - outParm.IsSucceed = true; - outParm.result = new - { - hzname = hzname, - url = repath, - tile = Path.GetFileNameWithoutExtension(file.FileName), - size, - DataPath = path, - filePath = dic - }; - } - catch (Exception e) - { - outParm.IsSucceed = false; - outParm.Message = $"文件上传失败!{e.Message}"; - } - return Json(outParm); - }); + return await Upload_Files(file); } #endregion }