From 8eaf9f54a0d0bbf1c9ae7da0e1f6b0216510c41a Mon Sep 17 00:00:00 2001 From: Santiago Osorio Date: Sat, 5 Dec 2015 14:52:01 -0600 Subject: [PATCH] Expose `originalFilename` property Filename is replaced when `getFilename` is set in the options, this commit sets a new property called `originalFilename` to keep the original filename (only works when you upload the file, after that you need to save it in a model). --- lib/storage-handler.js | 1 + test/upload-download.test.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/storage-handler.js b/lib/storage-handler.js index e0dabc6..ebdaa8d 100644 --- a/lib/storage-handler.js +++ b/lib/storage-handler.js @@ -68,6 +68,7 @@ exports.upload = function(provider, req, res, options, cb) { // Build a filename if ('function' === typeof options.getFilename) { + file.originalFilename = file.name; file.name = options.getFilename(file, req, res); } diff --git a/test/upload-download.test.js b/test/upload-download.test.js index edf705e..e592994 100644 --- a/test/upload-download.test.js +++ b/test/upload-download.test.js @@ -179,7 +179,7 @@ describe('storage service', function () { .expect('Content-Type', /json/) .expect(200, function (err, res) { assert.deepEqual(res.body, {"result": {"files": {"image": [ - {"container": "album1", "name": "image-test.jpg", "type": "image/jpeg", "acl":"public-read", "size": 60475} + {"container": "album1", "name": "image-test.jpg", "originalFilename":"test.jpg", "type": "image/jpeg", "acl":"public-read", "size": 60475} ]}, "fields": {}}}); done(); });