I was wondering if it is possible to get Busboy to analyze fields and files individually. (I removed bodyParser , since you can easily fill the hard drive with temp files.)
For example, middleware that processes post fields (used for all POST requests)
if (req.method === 'POST') { var form = new busboy({ headers: req.headers, limit: { files: 0 } }); form.on('field', function (fieldname, val, valTruncated, keyTruncated) { req.params.body[fieldname] = val; }); form.on('finish', function () { next(); }); return req.pipe(form); } else { next(); }
Then, on download pages, use the following, which Busboy uses to retrieve published files.
app.post('/fm/file/upload/:folder', function (req, res) { var isFrame = helpers.toBool(req.param('frame'), false), uploadService = fmUploadService.create(), userId = res.locals.info.User.Id, folder = helpers.toInt(req.param('folder', 0)); uploadService.processUploads(userId, folder, req, res, function (uploadError, allowedAccess, files) { if (uploadError) { if (req.xhr) { res.status(500); res.json(uploadError); } else { res.render('filemanager/file_upload.jade', { actionUrl: '/fm/file/upload/' + folder, tempData: files, isFrame: isFrame, err: uploadError }); } return; } else if (req.xhr) { res.status(200); res.json(files); return; } res.render('filemanager/file_upload.jade', { actionUrl: '/fm/file/upload/' + folder, tempData: files, isFrame: isFrame, err: null }); }); });
Currently, the files will always be 0, as Busboy is already running in the middleware.