From ee0f080ba76e60932992dca5f7cfc234d31b81bd Mon Sep 17 00:00:00 2001 From: Julien Vanier Date: Tue, 24 Jan 2017 15:53:05 -0500 Subject: [PATCH] Pass the preservePath down to Busboy --- README.md | 1 + index.js | 3 +++ lib/make-middleware.js | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe5934e0..d656cc23 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ Key | Description `dest` or `storage` | Where to store the files `fileFilter` | Function to control which files are accepted `limits` | Limits of the uploaded data +`preservePath` | Keep the full path of files instead of just the base name In an average web app, only `dest` might be required, and configured as shown in the following example. diff --git a/index.js b/index.js index 2a98039b..1e81733b 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ function Multer (options) { } this.limits = options.limits + this.preservePath = options.preservePath this.fileFilter = options.fileFilter || allowAll } @@ -45,6 +46,7 @@ Multer.prototype._makeMiddleware = function (fields, fileStrategy) { return { limits: this.limits, + preservePath: this.preservePath, storage: this.storage, fileFilter: wrappedFileFilter, fileStrategy: fileStrategy @@ -74,6 +76,7 @@ Multer.prototype.any = function () { function setup () { return { limits: this.limits, + preservePath: this.preservePath, storage: this.storage, fileFilter: this.fileFilter, fileStrategy: 'ARRAY' diff --git a/lib/make-middleware.js b/lib/make-middleware.js index 1210a6a9..7028fe79 100644 --- a/lib/make-middleware.js +++ b/lib/make-middleware.js @@ -23,13 +23,14 @@ function makeMiddleware (setup) { var storage = options.storage var fileFilter = options.fileFilter var fileStrategy = options.fileStrategy + var preservePath = options.preservePath req.body = Object.create(null) var busboy try { - busboy = new Busboy({ headers: req.headers, limits: limits }) + busboy = new Busboy({ headers: req.headers, limits: limits, preservePath: preservePath }) } catch (err) { return next(err) }