2

我正在尝试使用 busboy-connect 来解析我发送到服务器的请求文件。当我打印出我的请求对象时,我得到了这个巨大的 Angular.identity 对象,当我尝试使用以下代码解析对象时:

app.post("/compositions/fileUpload", function(req, res){
var fstream;

     req.pipe(req.busboy);

     req.busboy.on('file', function (fieldname, file, filename) {

        console.log("Uploading: " + filename); 

        fstream = fs.createWriteStream('/files/' + filename);

        file.pipe(fstream);

        fstream.on('close', function () {

            res.redirect('back');

        });
    });

我在“req.pipe(req.busboy)”上出错了。我确实需要 connect-busboy 和 fs。我还确保告诉我的应用程序使用 busboy,所以他们应该在那里。但是,我继续收到此错误:

TypeError: Cannot call method 'on' of undefined
    at IncomingMessage.Readable.pipe (_stream_readable.js:476:8)
    at Object.handle (/home/cyen/development/composelet/source/composelet/packages/compositions/server/routes/compositions.js:38:10)
    at next_layer (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/route.js:103:13)
    at Route.dispatch (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/route.js:107:5)
    at /home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:213:24
    at Function.proto.process_params (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:286:12)
    at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:207:19)
    at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
    at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
    at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
POST /compositions/fileUpload 500 136.347 ms - -

_stream_readable.js:483
    dest.end();
         ^
TypeError: Cannot call method 'end' of undefined
    at IncomingMessage.onend (_stream_readable.js:483:10)
    at IncomingMessage.g (events.js:180:16)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

我不知道为什么。似乎这里还有另一个类似的问题,尚未解决。有谁知道这个错误可能是由什么引起的?谢谢!

4

1 回答 1

2

问题是我在全局范围内的模块上方不需要(connect-busboy)。

于 2014-07-11T20:28:10.303 回答