详情见代码
This commit is contained in:
@@ -280,9 +280,17 @@ func serveUploadFile(w http.ResponseWriter, r *http.Request, dir, name string) {
|
||||
ct = "application/vnd.ms-excel"
|
||||
}
|
||||
w.Header().Set("Content-Type", ct)
|
||||
// 统一强制下载(Content-Disposition: attachment):文件名按 RFC 5987 编码(中文安全),
|
||||
// 浏览器直接下载不预览;<img>/<iframe> 内嵌展示不受此头影响
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape(filepath.Base(abs)))
|
||||
// 图片/PDF 内联预览(浏览器新标签页直接渲染,修复附件中心/工艺 PDF 预览变下载);
|
||||
// 其余类型强制下载;显式 dl=1 一律强制下载(对齐 WMS /uploads/ 行为)。
|
||||
// 文件名按 RFC 5987 编码(中文安全)。
|
||||
disp := "attachment"
|
||||
if isInlineExt(filepath.Ext(abs)) {
|
||||
disp = "inline"
|
||||
}
|
||||
if r.URL.Query().Get("dl") == "1" {
|
||||
disp = "attachment"
|
||||
}
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`%s; filename*=UTF-8''%s`, disp, url.PathEscape(filepath.Base(abs))))
|
||||
http.ServeContent(w, r, filepath.Base(abs), time.Time{}, f)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user