3

我有一个需要处理文件上传的快速应用程序,但由于某种原因它无法正常工作。我收到一条神秘的错误消息(nodejitsu/local),我不知道出了什么问题。

这是我的路线:

var routes = require('../routes');

module.exports = function(app) {
  app.get('/', routes.index);
  app.get('/import', routes.import.form);
  app.post('/import/upload', routes.import.submit);
};

这是我的功能:

exports.import = {
    form: function(req, res) {
        renderTemplate(res, 'form');
    },
    submit: function (req, res) {
        res.send(console.dir(req.files));
    }
}

这是我的 HTML:

<form role="form" action="/import/upload" method="post" enctype="multipart/form-data">
  <div class="form-group">
    <label for="exampleInputFile">Upload</label>
    <input type="file" id="csvFile">
    <p class="help-block">Please select .csv file.</p>
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

这是错误消息:

Error: Expected CR Received 45
at Form._write (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:187:49)
at doWrite (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/multiparty/node_modules/readable-stream/lib/_stream_writable.js:262:12)
at writeOrBuffer (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/multiparty/node_modules/readable-stream/lib/_stream_writable.js:249:5)
at Form.Writable.write (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/multiparty/node_modules/readable-stream/lib/_stream_writable.js:196:11)
at write (_stream_readable.js:583:24)
at flow (_stream_readable.js:592:7)
at _stream_readable.js:560:7
at process._tickCallback (node.js:415:13)
4

1 回答 1

12

input[type=file]没有name属性,这会扰乱 Express/Connect。

所以试试这个:

<input type="file" id="csvFile" name="csvFile">
于 2013-11-03T08:46:46.247 回答