From 2f37ce3a60ea6c02d0ed77082c7ecc7941882285 Mon Sep 17 00:00:00 2001 From: Jozz Hart Date: Thu, 6 Jun 2013 22:20:06 +0100 Subject: [PATCH 1/2] add .csv extension to the file download --- lib/express-csv.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/express-csv.js b/lib/express-csv.js index fcc1d69..b0a8cf2 100644 --- a/lib/express-csv.js +++ b/lib/express-csv.js @@ -84,7 +84,7 @@ function objToArray(obj) { /** * Send CSV response with `obj`, optional `headers`, and optional `status`. - * + * * @param {Array} obj * @param {Object|Number} headers or status * @param {Number} status @@ -93,10 +93,14 @@ function objToArray(obj) { */ res.csv = function(obj, headers, status) { + + var page = this.req.route.path.split('/').pop(); + var body = ''; this.charset = this.charset || 'utf-8'; this.header('Content-Type', 'text/csv'); + this.header('Content-disposition', 'attachment; filename=' + page + '.csv'); obj.forEach(function(item) { if (!(item instanceof Array)) item = objToArray(item); From 30bce2b0472dcaac711a51415023d8622a6bf48d Mon Sep 17 00:00:00 2001 From: Jozz Hart Date: Thu, 27 Jun 2013 10:35:23 +0200 Subject: [PATCH 2/2] File Disposition Only set file name if hasn't already been set previously --- lib/express-csv.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/express-csv.js b/lib/express-csv.js index b0a8cf2..e0cdfb6 100644 --- a/lib/express-csv.js +++ b/lib/express-csv.js @@ -100,7 +100,9 @@ res.csv = function(obj, headers, status) { this.charset = this.charset || 'utf-8'; this.header('Content-Type', 'text/csv'); - this.header('Content-disposition', 'attachment; filename=' + page + '.csv'); + if(this.get('Content-disposition') == null) + this.header('Content-disposition', 'attachment; filename=' + page + '.csv'); + obj.forEach(function(item) { if (!(item instanceof Array)) item = objToArray(item);