Skip to content

Commit f8a671a

Browse files
leonardypyangping
andauthored
fixed(api/v1/example/exa_excel.go): 下载模版失败 (flipped-aurora#916)
Co-authored-by: yangping <yangping@66nao.com>
1 parent e6366a9 commit f8a671a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

server/api/v1/example/exa_excel.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package example
22

33
import (
4+
"os"
5+
46
"github.com/flipped-aurora/gin-vue-admin/server/global"
57
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
68
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
7-
"github.com/flipped-aurora/gin-vue-admin/server/utils"
89
"github.com/gin-gonic/gin"
910
"go.uber.org/zap"
1011
)
@@ -89,12 +90,18 @@ func (e *ExcelApi) LoadExcel(c *gin.Context) {
8990
func (e *ExcelApi) DownloadTemplate(c *gin.Context) {
9091
fileName := c.Query("fileName")
9192
filePath := global.GVA_CONFIG.Excel.Dir + fileName
92-
ok, err := utils.PathExists(filePath)
93-
if !ok || err != nil {
93+
94+
fi, err := os.Stat(filePath)
95+
if err != nil {
9496
global.GVA_LOG.Error("文件不存在!", zap.Error(err))
9597
response.FailWithMessage("文件不存在", c)
9698
return
9799
}
100+
if fi.IsDir() {
101+
global.GVA_LOG.Error("不支持下载文件夹!", zap.Error(err))
102+
response.FailWithMessage("不支持下载文件夹", c)
103+
return
104+
}
98105
c.Writer.Header().Add("success", "true")
99106
c.File(filePath)
100107
}

0 commit comments

Comments
 (0)