Skip to content

Commit

Permalink
Merge pull request #37 from NicolasRitouet/add-data-in-upload-event
Browse files Browse the repository at this point in the history
Add data in upload event
  • Loading branch information
NicolasRitouet committed Oct 19, 2015
2 parents 9b51c32 + 84eea7f commit 0b55864
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Fileupload.prototype.handle = function (ctx, next) {
resultFiles = [],
remainingFile = 0,
storedObject = {},
uniqueFilename = false;
uniqueFilename = false,
subdir;

// Will send the response if all files have been processed
var processDone = function(err) {
Expand All @@ -97,7 +98,8 @@ Fileupload.prototype.handle = function (ctx, next) {

if (propertyName === 'subdir') {
debug("Subdir found: %j", req.query[propertyName]);
uploadDir = path.join(uploadDir, req.query[propertyName]);
subdir = req.query[propertyName];
uploadDir = path.join(uploadDir, subdir);
// If the sub-directory doesn't exists, we'll create it
try {
fs.statSync(uploadDir).isDirectory();
Expand Down Expand Up @@ -157,7 +159,14 @@ Fileupload.prototype.handle = function (ctx, next) {
file.name = md5(Date.now()) + '.' + file.name.split('.').pop();
}
if (self.events.upload) {
self.events.upload.run(ctx, {url: ctx.url, filesize: file.size, filename: ctx.url}, function(err) {
self.events.upload.run(ctx, {
url: ctx.url,
filesize: file.size,
filename: file.name,
originalFilename: file.originalFilename,
uniqueFilename: uniqueFilename,
subdir: subdir
}, function(err) {
if (err) return processDone(err);
renameAndStore(file);
});
Expand Down

0 comments on commit 0b55864

Please sign in to comment.