在使用busboy dest.end()错误上传文件时

时间:2016-12-13 12:12:12

标签: node.js file-upload busboy

我正在为用户个人资料更新创建节点api,而使用busboy上传文件则显示错误Cannot read property "end()" of undefined 以下是app.js的代码

 app.use(busboy());


  apiRoutes.post('/profileUpdate', function(req, res){
      var token=getToken(req.headers);
      var owner=jwt.decode(token, config.secret);
      var fstream;
      req.pipe(req.busboy);
      req.busboy.on('file', function(fieldname, file, filename){
        var filePath=path.join(__dirname,'public/file', filename);
        fstream=fs.createWriteStream(filePath);
        file.pipe(fstream);
        fstream.on('close', function(){
          console.log("FIle Saved");
        });

      });
    });

我尝试替换app.use(busboy());,但它没有用。请帮我解决这个错误。

由于

1 个答案:

答案 0 :(得分:0)

是您在尝试上传文件的前端请求multipart / form-data?因为Busboy不会解析请求,如果它不是multipart / form-data。