diff --git a/README.md b/README.md index 204c7a3..a16b2cd 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,8 @@ Other options and their default values: accessControl: { allowOrigin: '*', allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE' - } + }, + force: false // Overwrite files with the same name on upload } ``` diff --git a/index.js b/index.js index 0ebaf48..00bcdbe 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,8 @@ JqueryFileUploadMiddleware.prototype.prepareOptions = function (options) { accessControl: { allowOrigin: '*', allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE' - } + }, + force: false //Overwrite file with same name }, options); _.each(['uploadDir', 'uploadUrl'], function (key) { diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 070f018..d419a35 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -92,7 +92,9 @@ module.exports = function (options) { .on('fileBegin', function (name, file) { tmpFiles.push(file.path); var fileInfo = new FileInfo(file); - fileInfo.safeName(); + if(!options.force) { + fileInfo.safeName(); + } map[path.basename(file.path)] = fileInfo; files.push(fileInfo); self.emit('begin', fileInfo);