basically what i have is an Angular Web Page that uploads a file to the server through a POST which my NodeJS app receives.
My problem comes when i am trying to receive the file path through subirArchivo() and sending it through a function called InsertaPersonas(). I have tried several methods but it always results in the function being called undefined, it doesn't even enter the function once.
Here is my code:
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();
});
}
Here it is my whole class: https://pastebin.com/b8a2E3EZ