I am using formidable package to upload a file. This is my server side code.
var formidable = require('formidable'),
http = require('http'),
util = require('util');
app.post('/admin/uploads', function(req, res) {
console.log(req.files, req.fields);//It prints
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
console.log("Inside form parse.");//its not printing
console.log(err, fields, files);//its not printing
});
form.on('file', function(name, file) {console.log('file='+file);});//its not printing
form.on('error', function(err) { console.log(err); });//its not printing
form.on('aborted', function() { console.log('Aborted'); });//its not printing
console.log(form);//it prints
});
In the above code, form.parse() method is not invoke.Please give solution for this issue.
It might be that you need to remove body parser
delete app.use(express.bodyParser());
Please add the error handlers and send the error message otherwise it is hard to get an answer.
form.on('error', function(err) { console.log(err); });
form.on('aborted', function() { console.log('Aborted'); });
See the formidable
documentation : doc
Call form.parse(...)
after all on(...)
events.
app.post('/admin/uploads', function(req, res) {
var form = new formidable.IncomingForm();
form.on('file', function(name, file) { });
form.on('error', function(err) { });
form.on('aborted', function() { });
form.parse(req, function(err, fields, files) { });
});