From 1eab11ca900538d85e2af0260e1ba70e22721d0b Mon Sep 17 00:00:00 2001 From: ysqi Date: Wed, 23 Mar 2016 21:27:28 +0800 Subject: [PATCH 1/2] fixed #1815 check file before download --- context/output.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/context/output.go b/context/output.go index ea5498c0..0de3085c 100644 --- a/context/output.go +++ b/context/output.go @@ -24,6 +24,7 @@ import ( "io" "mime" "net/http" + "os" "path/filepath" "strconv" "strings" @@ -237,6 +238,13 @@ func (output *BeegoOutput) XML(data interface{}, hasIndent bool) error { // Download forces response for download file. // it prepares the download response header automatically. func (output *BeegoOutput) Download(file string, filename ...string) { + + // check get file error, file not found or other error. + if _, err := os.Stat(file); err != nil { + http.ServeFile(output.Context.ResponseWriter, output.Context.Request, file) + return + } + output.Header("Content-Description", "File Transfer") output.Header("Content-Type", "application/octet-stream") if len(filename) > 0 && filename[0] != "" { From b7d1afbf86117a5e85dcddf390ef62d3c850f854 Mon Sep 17 00:00:00 2001 From: YuShuangqi Date: Thu, 24 Mar 2016 08:35:42 +0800 Subject: [PATCH 2/2] Remote empty line --- context/output.go | 1 - 1 file changed, 1 deletion(-) diff --git a/context/output.go b/context/output.go index 0de3085c..3568d89c 100644 --- a/context/output.go +++ b/context/output.go @@ -238,7 +238,6 @@ func (output *BeegoOutput) XML(data interface{}, hasIndent bool) error { // Download forces response for download file. // it prepares the download response header automatically. func (output *BeegoOutput) Download(file string, filename ...string) { - // check get file error, file not found or other error. if _, err := os.Stat(file); err != nil { http.ServeFile(output.Context.ResponseWriter, output.Context.Request, file)