简体   繁体   中英

Express.js with csv-parse

I am trying to get the data that is inside a csv file.

I send the file through Insomnia, then the multer is in charge of accessing the csv file and providing me with its buffer.

To get the csv data, I am using csv-parse .

However, despite the data appearing in the terminal, I always get the following error:

Error: ENAMETOOLONG: name too long, open 'uuid,first_name,last_name,birthday

I'm not really understanding what's going on.

Here is an code snippet:

import fs from 'fs'
import parse from 'csv-parse'

const result = []
fs.createReadStream(msg.content).pipe(parse()).on('data', (data) => {
  data.forEach(user => {
    result.push(user)
  })
})

msg.content is the csv buffer.

Thank you and have a great day!

I think you are trying to pass csv content as file handle (name). if msg.content is not a file handle, but a whole buffer with csv inside, you should not use fs.createReadStream , but use stream.Readable . This should solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM