Essentially, I have an Angular Web Page that uploads a file to the server via a POST request, which is then received by my NodeJS app.
The issue arises when attempting to retrieve the file path in subirArchivo() and pass it to a function called InsertaPersonas(). Despite trying various approaches, the function always ends up being called as undefined and does not execute even once.
Below is the code snippet:
subirArchivo(req: Request, res: Response) {
var form = new IncomingForm();
let readStream;
var self = this;
this.insertaPersonas('a'); // function undefined
form.parse(req);
form.on('file', (field: any, file: any) => {
// Do something with the file
// e.g. save it to the database
// you can access it using file.path
console.log('file', file.name); //this works
readStream = fs.createReadStream(file.path); // this works
// console.log(file.path); //this works
self.insertaPersonas(file.path); //function undefined
});
form.on('end', () => {
res.json();
});
}
For the complete class code, visit: https://pastebin.com/b8a2E3EZ