Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created October 1, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcnally/3813103 to your computer and use it in GitHub Desktop.
Save j-mcnally/3813103 to your computer and use it in GitHub Desktop.
fileHandler.js
module.exports = function fileHandler(){
return function fileHandler(req, res, next){
if (req.form) {
req.form.complete(function(err, fields, files){
var flatFiles = [];
for(var key in files) {
if (files[key] instanceof Array) {
for(var i = 0; i < files[key].length; i++) {
flatFiles.push(files[key][i]);
}
}
else {
flatFiles.push(files[key]);
}
}
req.files = flatFiles;
next();
});
}
else {
next();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment