Commit 2362ca00 authored by astaxie's avatar astaxie

Merge pull request #1827 from ysqi/issue

Check file before download
parents 9f18813c b7d1afbf
......@@ -24,6 +24,7 @@ import (
"io"
"mime"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
......@@ -237,6 +238,12 @@ 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] != "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment