Skip to content

Instantly share code, notes, and snippets.

@dawnerd
Created July 10, 2012 00:47
Show Gist options
  • Save dawnerd/3080240 to your computer and use it in GitHub Desktop.
Save dawnerd/3080240 to your computer and use it in GitHub Desktop.
Image upload for nodejs & formidable
var form = new formidable.IncomingForm(),
files = [];
form.uploadDir = config.tmpPath;
form.maxFieldsSize = config.maxUploadSize;
form
.on('file', function(field, file) {
files.push([field, file]);
})
.on('end', function() {
//Add the files to mongo and move
PhotosModel.on('error', function(msg){
console.log(msg);
req.flash('error', msg);
});
for(var i = 0, c = files.length; i < c; i++) {
PhotosModel.add(files[i]);
}
req.flash('info', 'Uploaded files are being processed and will show up on the manage page when they are complete.');
res.redirect('/admin/photo/upload');
res.end();
});
form.parse(req);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment