From 1f08356eb1d07953f7f0262ff6c879af16c4b98c Mon Sep 17 00:00:00 2001 From: yhw0507 Date: Thu, 21 Dec 2023 17:45:54 +0800 Subject: [PATCH] =?UTF-8?q?20231221=E8=8E=B7=E5=8F=96=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E6=8C=89=E7=85=A7=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DoorProject/uploadController.cs | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/SGGL/WebAPI/Controllers/DoorProject/uploadController.cs b/SGGL/WebAPI/Controllers/DoorProject/uploadController.cs index a3886a51..2e4f7af3 100644 --- a/SGGL/WebAPI/Controllers/DoorProject/uploadController.cs +++ b/SGGL/WebAPI/Controllers/DoorProject/uploadController.cs @@ -266,32 +266,21 @@ namespace WebAPI.Controllers } else { - if (string.IsNullOrEmpty(getPerson.PhotoUrl) && (person.headImage.Length > 0 || !string.IsNullOrEmpty(person.PhotoUrl))) + if (person.headImage.Length > 0) { - if (person.headImage.Length == 0 && !string.IsNullOrEmpty(person.PhotoUrl)) + var image = Convert.FromBase64String(person.headImage); + getPerson.HeadImage = image; + string rootPath = ConfigurationManager.AppSettings["localRoot"]; + string path = "FileUpLoad/PersonBaseInfo/" + DateTime.Now.ToString("yyyy-MM") + "/"; + string fileUrl = (rootPath + path).Replace('/', '\\'); + string flieName = Funs.GetNewFileName() + "~" + person.PersonName + ".jpg"; + if (!Directory.Exists(fileUrl)) { - var getS = AttachFileService.SetImageToByteArray(person.PhotoUrl); - if (getS != null) - { - person.headImage = getS.ToString(); - } - } - if (person.headImage.Length > 0) - { - var image = Convert.FromBase64String(person.headImage); - getPerson.HeadImage = image; - string rootPath = ConfigurationManager.AppSettings["localRoot"]; - string path = "FileUpLoad/PersonBaseInfo/" + DateTime.Now.ToString("yyyy-MM") + "/"; - string fileUrl = (rootPath + path).Replace('/', '\\'); - string flieName = Funs.GetNewFileName() + "~" + person.PersonName + ".jpg"; - if (!Directory.Exists(fileUrl)) - { - Directory.CreateDirectory(fileUrl); - } - getPerson.PhotoUrl = path + flieName; - System.IO.File.WriteAllBytes((fileUrl + flieName), image); - //AttachFileService.Base64ToImage(person.headImage, path, person.PersonName); + Directory.CreateDirectory(fileUrl); } + getPerson.PhotoUrl = path + flieName; + System.IO.File.WriteAllBytes((fileUrl + flieName), image); + //AttachFileService.Base64ToImage(person.headImage, path, person.PersonName); db.SubmitChanges(); responeData.message = "更新照片!"; }