node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

How to read base64 csv file?

Open kuriel-trivu opened this issue 2 years ago • 3 comments

our uploaded file is a base64 encoded string, i think this is very popular nowadays, how to read that kind of files? with this module.

kuriel-trivu avatar Mar 29 '22 19:03 kuriel-trivu

Use node fromStream method with createReadStream

const fs = require('fs')
const csv = require('csvtojson')

csv()
  .fromStream(fs.createReadStream('/path/to/file', { encoding: 'base64' }))
  .subscribe((json) => {
    console.log(json)
  },
  (err) => {
    throw err
  },
  () => {
    console.log('success')
  })

jfoclpf avatar Apr 22 '22 08:04 jfoclpf

@jfoclpf Bro, title Is VERY specific. From base64 string, you passed a path file.

kuriel-trivu avatar Apr 22 '22 14:04 kuriel-trivu

got it, though IMHO it is not a purpose of this module to do this type of conversions, anyway you can check this

https://stackoverflow.com/questions/48534404/create-readstream-from-base64-encoded-string-by-file

jfoclpf avatar Apr 22 '22 16:04 jfoclpf