fileDownController.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * @Author: liling
  3. * @Date: 2022-08-13 14:38:13
  4. * @LastEditors: liling
  5. * @LastEditTime: 2022-08-13 14:38:15
  6. * @FilePath: \police_security\controllers\exelController.go
  7. * @Description:excel导入导出相关控制器
  8. *
  9. * Copyright (c) 2022 by liling/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "path"
  14. )
  15. type FileDownController struct {
  16. BaseController
  17. }
  18. func init() {
  19. }
  20. // @Summary 公用文件下载方法
  21. // @Description 公用文件下载方法.可通过该方法实现对目标文件进行下载权限、过虑、记录等操作
  22. // @Tags 文件/附件服务接口
  23. // @Accept x-www-form-urlencoded
  24. // @Produce json
  25. // @Param path query string true "需要下载的文件路径"
  26. // @Param save_name query string false "文件名称"
  27. // @Success 200 {object} ResultOK 成功
  28. // @Failure 500 {object} ResultError 失败
  29. // @router /file/download [get]
  30. func (this *FileDownController) Get() {
  31. //图片,text,pdf文件全部在浏览器中显示了,并没有完全的实现下载的功能
  32. //this.Redirect("/static/img/1.jpg", 302)
  33. //第一个参数是文件的地址,第二个参数是下载显示的文件的名称
  34. //this.Ctx.Output.Download("static/img/1.jpg", "tu1.jpg")
  35. realPath := this.GetString("path")
  36. fn := this.GetString("save_name")
  37. if fn == "" {
  38. fn = path.Base(realPath)
  39. }
  40. this.Ctx.Output.Download(realPath, fn)
  41. }