I’m trying to make a REST API that allowes users to Upload a CSV in Order to write the data into a Database.
However, I seem to be having issues going from ArrayBuffer to readable lines.
I’m running a Google Cloud Function that uses Express. I’m running my function locally and I’ve tried parsing the File via the Body either as form-data or directly as binary in the body (via Postman).
`import csv from’csv-parser’;
import multer from ‘multer’
import fs from ‘fs’
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });
app.post(“/upload”, upload.single(‘csvFile’), async(req, res) => {
const buffer = new Uint8Array(req.body)
fs.createReadStream(buffer)
.pipe(csv())
.on('data', (row) => {
console.log(row);
})
.on('end', () => {
res.send('File uploaded and processed successfully');
});
})`
This is the furthers I’ve gotten. However fs seems to be trying to open the File as it throws the Error ENAMETOOLONG and enteres the entire data.
Rhys Werner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.