Просмотр исходного кода

set attachment filename when download through browser

Hunter Kehoe 2 лет назад
Родитель
Сommit
4fa0655438
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      server/server.go

+ 3 - 0
server/server.go

@@ -642,6 +642,9 @@ func (s *Server) handleFile(w http.ResponseWriter, r *http.Request, v *visitor)
 		return err
 	}
 	defer f.Close()
+	if m.Attachment.Name != "" {
+		w.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(m.Attachment.Name))
+	}
 	_, err = io.Copy(util.NewContentTypeWriter(w, r.URL.Path), f)
 	return err
 }