添加删除文件接口

This commit is contained in:
曾艳 2024-06-14 09:29:55 +08:00
parent 37ed5273fc
commit 9c323ddebe
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using Competition.Common.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace CompetitionAPI.Controllers.version
{
[Route("api/[controller]")]
[ApiController]
public class DeleteFileController : Controller
{
private readonly IWebHostEnvironment _webHostEnvironment;
public DeleteFileController(IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
}
/// <summary>
/// 删除文件接口
/// </summary>
/// <param name="Path">文件路径</param>
/// <returns></returns>
[HttpGet]
public JsonResult Index(string Path)
{
var webRootPath = _webHostEnvironment.WebRootPath;
if (System.IO.File.Exists(webRootPath + "/" + Path))
{
System.IO.File.Delete(webRootPath + "/" + Path);
}
return Json(Tool.GetJsonWithCode(APICode.Success, "删除成功"));
}
}
}