[英]Cannot read property pipe of undefined in csv parser
I am trying to upload a large csv file of 10mb using csv parser and form data in node js while sending a request to an api with axios.我正在尝试使用 csv 解析器上传 10mb 的大型 csv 文件并在节点 js 中形成数据,同时使用 axios 向 api 发送请求。 My code is the following:我的代码如下:
//insert new data
else if (`${flags.newdata}` !== "undefined" && `${flags.source}` !== "undefined" ){
var csv=require('csv-parser');
var FormData=require('form-data');
const form_data = new FormData();
var data = [];
form_data.append("file", fs.createReadStream(`${flags.source}`)).pipe(csv()).on('data',function(row){ data.push(row) }).on('end',function(){console.log('Data Loaded')});
/*const request_config = {
headers: {
"Authorization": token,
"Content-Type": "multipart/form-data"
},
data: form_data
};*/
return axios.post('https://localhost:8765/energy/api/Admin/' + `${flags.newdata}`, form_data);
}
I get the following error:我收到以下错误:
TypeError: Cannot read property 'pipe' of undefined
I have read similar questions but none helped.我读过类似的问题,但没有帮助。 How can I solve this?我该如何解决这个问题?
Looks like you want to pipe not a stream but result of append() but append return undefined.看起来您想通过管道传输的不是流而是 append() 的结果,但 append 返回未定义。 Please use pipe like this:请像这样使用管道:
var readStream = fs.createReadStream(`${flags.source}`);
readStream.on('open', function () {
readStream.pipe(csv());
});
readStream
.on('data',function(row){ data.push(row) })
.on('end',function(){console.log('Data Loaded')});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.