FileController.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.WebApi.Controllers
  12. {
  13. [Route("[controller]/[action]")]
  14. [ApiController]
  15. [AuthorizeFilter]
  16. public class FileController : ControllerBase
  17. {
  18. #region 上传单个文件
  19. [HttpPost]
  20. public async Task<TData<string>> UploadFile(int fileModule, IFormCollection fileList)
  21. {
  22. TData<string> obj = await FileHelper.UploadFile(fileModule, fileList.Files);
  23. return obj;
  24. }
  25. #endregion
  26. #region 删除单个文件
  27. [HttpPost]
  28. public TData<string> DeleteFile(int fileModule, string filePath)
  29. {
  30. TData<string> obj = FileHelper.DeleteFile(fileModule, filePath);
  31. return obj;
  32. }
  33. #endregion
  34. #region 下载文件
  35. [HttpGet]
  36. public FileContentResult DownloadFile(string filePath, int delete = 1)
  37. {
  38. TData<FileContentResult> obj = FileHelper.DownloadFile(filePath, delete);
  39. if (obj.Success)
  40. {
  41. return obj.Data;
  42. }
  43. else
  44. {
  45. throw new Exception("下载失败:" + obj.Message);
  46. }
  47. }
  48. #endregion
  49. }
  50. }