Send back rows and readstream in nodejs

98 Views Asked by At

Hey I would like to send back an image downloaded from s3 and data from MySQL database but i'm not sure if its even possible and if it is, how to do it.

Any help is welcome thanks!

app.get('/api/users/:id', (req, res) => {
    var id = req.params.id;
    pool.getConnection((err, connection) => {
        if (err) throw err
        console.log('connected as id ' + connection.threadId)
        connection.query(`SELECT username, picture, DATE_FORMAT(creation_date, "%d %M %Y") as creation_date from users where idusers = ${id}`, (err, rows) => {
            connection.release() // return the connection to pool

            if (!err) {
                
                const readStream = getFileStream(rows[0].picture);
                readStream.pipe(res);

                res.send(rows[0])
            } else {
                console.log(err)
            }
        })
    });
})
0

There are 0 best solutions below