0

我无法使用 Connect 框架上传文件。我参考了链接Connect。下面是我的代码

app.use(connectDomain())
    .use(connectRoute(function (router) {
        router.post('/upload', function (req, res) {
            var form = new formidable.IncomingForm();
            form.parse(req, function (err, fields, files) {
                res.writeHead(200, {'content-type': 'text/plain'});
                res.write('received upload:\n\n');
                res.end(JSON.stringify({fields: fields, files: files}));
            });

我总是得到如下响应

received upload:

{"fields":{},"files":{}}
4

1 回答 1

0

强大模块中给出的示例..

    var files = [],
    fields = [];
form
  .on('field', function(field, value) {
    console.log(field, value);
    fields.push([field, value]);
  })
  .on('file', function(field, file) {
    console.log(field, file);
    files.push([field, file]);
  })
  .on('end', function() {
    console.log('-> upload done');
    res.writeHead(200, {'content-type': 'text/plain'});
    res.write('received fields:\n\n '+util.inspect(fields));
    res.write('\n\n');
    res.end('received files:\n\n '+util.inspect(files));
  });
form.parse(req);
于 2014-11-14T06:18:51.880 回答