From 0e62541f9f186b3cbb18e2735ca23bac15be6984 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 5 Jun 2015 08:44:40 +0100 Subject: [PATCH] Gracefully handle error when uploadDir path is inside a file --- lib/uploadhandler.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 070f018..bc37fed 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -142,6 +142,13 @@ module.exports = function (options) { generatePreviews(); finish(); } else { + if (err.code === 'ENOTDIR') { + // Tried to rename to a path inside a file + fs.unlink(file.path); + self.emit('error', err); + return; + } + var is = fs.createReadStream(file.path); var os = fs.createWriteStream(options.uploadDir() + '/' + fileInfo.name); is.on('end', function (err) {