Created
July 10, 2012 00:47
-
-
Save dawnerd/3080240 to your computer and use it in GitHub Desktop.
Image upload for nodejs & formidable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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