1

我使用Busboy的是在本地存储文件。下面是我的代码:

apiRoutes.post('/upload' ,function(req, res){
  var fstream;
        req.pipe(req.busboy);
        req.busboy.on('file', function (fieldname, file, filename) {
            console.log("Uploading: " + filename);

            //Path where image will be uploaded
            fstream = fs.createWriteStream(__dirname + '/img/' + filename);
            file.pipe(fstream);
            fstream.on('close', function () {    
                console.log("Upload Finished of " + filename);              
                res.redirect('back');           
            });
        });

});

此代码在普通的单独项目中运行良好。但是当我在我的项目中使用这个中间件时,它会显示一个错误:

_stream_readable.js:498
dest.end();

TypeError: Cannot read property 'end' of undefined
     at onend(_stream_readable.js:498:9)
     at _combinedTickCallback(node.js:370:9)
     at process._tickCallback(node.js:401:11)

我用谷歌搜索但没有找到任何解决方案。请查看此代码并帮助我。

答案将不胜感激。

谢谢

4

0 回答 0