From d538d2c3bc879a9cc7ad2f1e44dd27460a7ecca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=87=E9=98=B3=20=E9=82=B9?= Date: Wed, 27 Dec 2023 18:56:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E4=B8=80=E4=B8=AA=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8C=85=E6=96=87=E4=BB=B6=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=9D=A5=E6=B8=85=E7=90=86=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=8C=85=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24Hour/Controllers/Common/CommonController.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/24Hour/Controllers/Common/CommonController.cs b/24Hour/Controllers/Common/CommonController.cs index bb2c4ec..cd2cac7 100644 --- a/24Hour/Controllers/Common/CommonController.cs +++ b/24Hour/Controllers/Common/CommonController.cs @@ -2771,6 +2771,43 @@ namespace _24Hour.Controllers.Common return BadRequest(); } } + + /// + /// 通用文件下载接口 + /// + /// + /// + [HttpGet] + [Route("RequestDeleteFile")] + public Result RequestDeleteFile(string filename) //[FromBody] dynamic Json + { + + if (System.IO.File.Exists(filename)) + { + filename = filename.Replace(@"\\", @"\"); + var data = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot"); + if (filename.Contains(data) == false) + { + return Result.Error("操作失败" + "不可删除"); + } + var FileName = System.IO.Path.GetFileName(filename); + var FilePath = filename; + try + { + System.IO.File.Delete(filename); + } + catch(Exception ex) + { + return Result.Error("操作失败"+ex.Message); + } + + return Result.Success("操作成功"); + } + else + { + return Result.Error("操作失败" + "文件不存在"); + } + } private readonly string[] AllowedExtensions = new string[] { ".png", ".jpg", ".jpeg", ".bmp", ".xlsx", ".aks" }; /// /// 文件上传--附件