如何在nodejs发布请求中获取文件路径以在文件中写入一些数据

时间:2019-04-03 06:11:24

标签: node.js multer

我正在将一个csv文件上传到服务器,并且在nodejs的发布请求中,我想最后再添加一行,上传时csv文件已经具有标题了。

   var multer = require('multer');
   var storage = multer.memoryStorage();
   var csvWriter = require('csv-write-stream');
   var writer = csvWriter({sendHeaders: false});

   var upload = multer({ 
            storage: storage
            }).single('file');



     exports.uploadContact =(req, res) => {

      upload(req, res, function (err) {

   writer = csvWriter({sendHeaders: false});

   writer.pipe(fs.createWriteStream(req.file.fieldname,{flags: 'a'}));

   writer.write({first_name: 'hahahaha'});

   writer.end();
                  });
                      }

我试图在标题“ first_name”下面的最后一行中添加“ haha​​ha”,但没有用

0 个答案:

没有答案