mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:40:54 +00:00
fixed #1815 check file before download
This commit is contained in:
parent
c4276d31c5
commit
1eab11ca90
@ -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] != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user