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