From cd9207804348fac3ef0445036dfe3a2e881e3ff8 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Wed, 1 Oct 2014 17:53:30 +0900 Subject: [PATCH] Add download query parameter to download images as attachment. --- lib/units/storage/plugins/image/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/units/storage/plugins/image/index.js b/lib/units/storage/plugins/image/index.js index 9fe4d2b9..88b16d31 100644 --- a/lib/units/storage/plugins/image/index.js +++ b/lib/units/storage/plugins/image/index.js @@ -31,6 +31,12 @@ module.exports = function(options) { }) .then(function(out) { res.status(200) + + if (typeof req.query.download !== 'undefined') { + res.set('Content-Disposition', + 'attachment; filename="' + req.params['0'] + '"') + } + out.pipe(res) }) .catch(function(err) {