From b45f0b9bf66c5a5a12b4c204cc5cd07de8110658 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 17 May 2014 02:56:50 +0800 Subject: [PATCH] beego: fix #478 --- context/output.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/context/output.go b/context/output.go index 06b3d717..8011392f 100644 --- a/context/output.go +++ b/context/output.go @@ -237,10 +237,14 @@ 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) { +func (output *BeegoOutput) Download(file string, filename ...string) { output.Header("Content-Description", "File Transfer") output.Header("Content-Type", "application/octet-stream") - output.Header("Content-Disposition", "attachment; filename="+filepath.Base(file)) + if len(filename) > 0 && filename[0] != "" { + output.Header("Content-Disposition", "attachment; filename="+filename[0]) + } else { + output.Header("Content-Disposition", "attachment; filename="+filepath.Base(file)) + } output.Header("Content-Transfer-Encoding", "binary") output.Header("Expires", "0") output.Header("Cache-Control", "must-revalidate")