From 848d5b51c0649eeef8c09a17d137d6f280629530 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Fri, 8 May 2020 15:26:39 +0800 Subject: [PATCH] 提交 --- src/HttpServer/logic/httpserver.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index a1a9c79..8d902e9 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -5,6 +5,7 @@ import ( "HttpServer/redishandler" "common/logger" "fmt" + "io" "io/ioutil" "mysql" "os" @@ -102,8 +103,19 @@ func QueryAllAccount(w http.ResponseWriter, r *http.Request) { f, _ = os.Create(filename) //创建文件 mysql.QueryAllData(f) + + fileHeader := make([]byte, 512) + f.Read(fileHeader) + fileStat, _ := f.Stat() + + w.Header().Set("Content-Disposition", "attachment; filename=" + filename) + w.Header().Set("Content-Type", http.DetectContentType(fileHeader)) + w.Header().Set("Content-Length", strconv.FormatInt(fileStat.Size(), 10)) + + f.Seek(0, 0) + io.Copy(w, f) //io.Copy(f,r.Body) - fmt.Fprint(w,f) + fmt.Fprint(w,"success") } -- libgit2 0.21.0