1

I'm using node-formidable for handling form data in Express/Nodejs app. I'm sending POST vars from POSTman Chrome Extension. (btw, http://httpbin.org/post works fine)

If i use multipart/form-data, everything is fine.

If i use urlencoded, form.parse's callback never triggers, and blocks all response. it simply locks the post method.

required:

var formidable = require('formidable');
var http = require('http');
var util = require('util');

post method:

app.post("/items",function(req,res){
    var form = new formidable.IncomingForm();
    form.parse(req,function(err,fields,files){
        console.log(fields);
        res.send("posted");
     });
});

express settings:

app.use(express.json());
app.use(express.urlencoded());
app.use(express.multipart());
app.use(express.cookieParser());
app.use(express.static(__dirname + '/public'));
app.use(express.cookieSession({secret:"wow_so_secret_such_code_gud_layers"}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());

is there any trick for using urlencoded?

might be important;

{ 
  domain: null,
  _events: {},
  _maxListeners: 10,
  error: null,
  ended: false,
  maxFields: 1000,
  maxFieldsSize: 2097152,
  keepExtensions: false,
  uploadDir: '/var/folders/pl/xnl7cxpj075chytyf_t7f1480000gn/T/',
  encoding: 'utf-8',
  headers: null,
  type: null,
  hash: false,
  bytesReceived: null,
  bytesExpected: null,
  _parser: null,
  _flushing: 0,
  _fieldsSize: 0,
  openedFiles: [] 
}

both urlencoded and multipart returns null.

Onur Özkan
  • 918
  • 1
  • 10
  • 20
  • If you are using `formidable` to parse incoming form, you need not use `multipart()` – vmx Dec 17 '13 at 21:26
  • @vmx removed multipart line, but no effect. same again. – Onur Özkan Dec 17 '13 at 21:42
  • try adding these: `form.encoding = 'utf-8';` `form.type = 'multipart';` before you do `form.parse()` – vmx Dec 17 '13 at 23:06
  • 1
    add `enctype="multipart/form-data"` in the html form tag as well. – vmx Dec 17 '13 at 23:07
  • see this for a working example: http://stackoverflow.com/a/20372845/1520518 – vmx Dec 17 '13 at 23:08
  • @vmx i'm trying to use urlencoded, not multipart. so these solutions does not work either. – Onur Özkan Dec 18 '13 at 11:45
  • btw, after i remove app.use(express.urlencoded()) it worked, but still no form.type value in form object. and i think there is still some problem with my forms. – Onur Özkan Dec 18 '13 at 11:46
  • The link I shared does not require you to use `multipart()`, I have mentioned to avoid using `multipart` – vmx Dec 18 '13 at 13:18

0 Answers0