Commit 848d5b51c0649eeef8c09a17d137d6f280629530
1 parent
7d9c133f
Exists in
master
提交
Showing
1 changed file
with
13 additions
and
1 deletions
Show diff stats
src/HttpServer/logic/httpserver.go
| ... | ... | @@ -5,6 +5,7 @@ import ( |
| 5 | 5 | "HttpServer/redishandler" |
| 6 | 6 | "common/logger" |
| 7 | 7 | "fmt" |
| 8 | + "io" | |
| 8 | 9 | "io/ioutil" |
| 9 | 10 | "mysql" |
| 10 | 11 | "os" |
| ... | ... | @@ -102,8 +103,19 @@ func QueryAllAccount(w http.ResponseWriter, r *http.Request) { |
| 102 | 103 | f, _ = os.Create(filename) //创建文件 |
| 103 | 104 | |
| 104 | 105 | mysql.QueryAllData(f) |
| 106 | + | |
| 107 | + fileHeader := make([]byte, 512) | |
| 108 | + f.Read(fileHeader) | |
| 109 | + fileStat, _ := f.Stat() | |
| 110 | + | |
| 111 | + w.Header().Set("Content-Disposition", "attachment; filename=" + filename) | |
| 112 | + w.Header().Set("Content-Type", http.DetectContentType(fileHeader)) | |
| 113 | + w.Header().Set("Content-Length", strconv.FormatInt(fileStat.Size(), 10)) | |
| 114 | + | |
| 115 | + f.Seek(0, 0) | |
| 116 | + io.Copy(w, f) | |
| 105 | 117 | //io.Copy(f,r.Body) |
| 106 | - fmt.Fprint(w,f) | |
| 118 | + fmt.Fprint(w,"success") | |
| 107 | 119 | } |
| 108 | 120 | |
| 109 | 121 | ... | ... |