I am using the formidable
package to handle file uploads on my server.
This is my express.js
app 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, the form.parse
and form.on
callbacks are never run. How can I solve this issue?