From 25473e80d9fe46b013eb785b28eab801e5c38f43 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 2 Jan 2014 07:06:03 +0300 Subject: [PATCH] can use handler event --- README.md | 18 ++++++++++++++++++ lib/filehandler.js | 2 ++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 7110a2d..72d1ce5 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,24 @@ Other options and their default values: } ``` +Use event: +[full sample](https://github.com/Pechalka/file_upload_demo) + +```javascript + var doc_id = req.url.split('/')[1]; // /uploads/2 => 2 - doc_id + upload.fileHandler({ + uploadDir: __dirname + '/../public/uploads/' + doc_id, + uploadUrl: '/../uploads/' + doc_id + })(req, res) + .on('end', function(fileInfo){ + add_file(fileInfo.name, doc_id); + }) + .on('delete', function(file_name){ + remove_fie(file_name, doc_id); + }) +``` + + ## Contributors * [@soomtong](http://github.com/soomtong) diff --git a/lib/filehandler.js b/lib/filehandler.js index bab6f89..1bbeabe 100644 --- a/lib/filehandler.js +++ b/lib/filehandler.js @@ -53,5 +53,7 @@ module.exports = function (middleware, options) { default: res.send(405); } + + return handler; } };