I want to parse a csv file coming from a react app. I have a controller which gets the csv file:
@Post(':id/transactions/upload')
@UseInterceptors(FileInterceptor('file'))
uploadTransactions(
@Body() body: any,
@UploadedFile() file: Express.Multer.File,
) {
return this.accountsUsersService.uploadTransactions(file.buffer);
}
and following service:
async uploadTransactions(buffer) {
console.log('### buffer', buffer);
const readBuffer = buffer.toString();
console.log('### readBuffer', readBuffer);
const csvData = [];
createReadStream(buffer) // tried many tings
.pipe(
parse({
delimiter: ';',
})
.on('data', function (dataRow) {
csvData.push(dataRow);
})
.on('end', function() {
console.log('### csvData', csvData)
})
)
return 'uploaded transactions successfully';
}
Here are the console.logs:
### buffer <Buffer 61 6c 62 65 72 74 3b 74 65 73 74 0a 6a 6f 61 6e 61 3b 67 6f 6f 64 0a>
### readBuffer albert;test
joana;good
Error: ENOENT: no such file or directory, open 'albert;test
joana;good
'
and here is the csv file:
albert;test
joana;good
Could someone clarify what am I missing?