|
@@ -121,3 +121,28 @@ func (c *BaseController) uploadStringToAliOSS(fStr string) (string, error) {
|
121
|
121
|
|
122
|
122
|
return fileURL, nil
|
123
|
123
|
}
|
|
124
|
+
|
|
125
|
+// SaveNetFilesToZip 压缩远程文件并下载
|
|
126
|
+func (c *BaseController) SaveNetFilesToZip(files []utils.NetFile, zf string) {
|
|
127
|
+ var buf bytes.Buffer
|
|
128
|
+
|
|
129
|
+ err := utils.ZipNetFiles(files, &buf)
|
|
130
|
+ if err != nil {
|
|
131
|
+ c.ResponseError(errors.New("下载 zip 文件失败"))
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.QueryEscape(zf))
|
|
135
|
+ c.Ctx.Output.Header("Content-Description", "File Transfer")
|
|
136
|
+ c.Ctx.Output.ContentType("application/zip")
|
|
137
|
+ c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
138
|
+ c.Ctx.Output.Header("Expires", "0")
|
|
139
|
+ c.Ctx.Output.Header("Cache-Control", "must-revalidate")
|
|
140
|
+ c.Ctx.Output.Header("Pragma", "public")
|
|
141
|
+
|
|
142
|
+ r := bytes.NewReader(buf.Bytes())
|
|
143
|
+ http.ServeContent(c.Ctx.ResponseWriter, c.Ctx.Request, zf, time.Now().Local(), r)
|
|
144
|
+
|
|
145
|
+ c.destroyContext(true)
|
|
146
|
+ c.StopRun()
|
|
147
|
+
|
|
148
|
+}
|