Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
2362ca00
Commit
2362ca00
authored
Mar 24, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1827 from ysqi/issue
Check file before download
parents
9f18813c
b7d1afbf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
output.go
context/output.go
+7
-0
No files found.
context/output.go
View file @
2362ca00
...
...
@@ -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
]
!=
""
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment