FileController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.AspNetCore.Mvc;
  8. using YiSha.Util;
  9. using YiSha.Util.Extension;
  10. using YiSha.Util.Model;
  11. namespace YiSha.Admin.Web.Controllers
  12. {
  13. public class FileController : BaseController
  14. {
  15. #region 上传单个文件
  16. [HttpPost]
  17. public async Task<TData<string>> UploadFile(int fileModule, IFormCollection fileList)
  18. {
  19. TData<string> obj = await FileHelper.UploadFile(fileModule, fileList.Files);
  20. obj.Data = HttpContext.Request.Scheme + "://" + HttpContext.Request.Host.Value + obj.Data;
  21. return obj;
  22. }
  23. #endregion
  24. #region 删除单个文件
  25. [HttpPost]
  26. public TData<string> DeleteFile(int fileModule, string filePath)
  27. {
  28. TData<string> obj = FileHelper.DeleteFile(fileModule, filePath);
  29. return obj;
  30. }
  31. #endregion
  32. #region 下载文件
  33. //[HttpGet]
  34. //public FileContentResult DownloadFile(string filePath, int delete = 1)
  35. //{
  36. // TData<FileContentResult> obj = FileHelper.DownloadFile(filePath, delete);
  37. // if (obj.Success)
  38. // {
  39. // return obj.Data;
  40. // }
  41. // else
  42. // {
  43. // throw new Exception("下载失败:" + obj.Message);
  44. // }
  45. //}
  46. #endregion
  47. }
  48. }