Im using jsftp in an express application to serve a string representation of an image from a FTP connection, which is working fine. However, the image does not display when sending it to the client:
router.get('/', (req, res, next) => {
let str = ''
ftp.get('/uploads/test.png', function (err, socket) {
if (err) return
socket.on('data', function (d) { str += d.toString() })
socket.on('close', function (hadErr) {
if (hadErr) {
console.error('There was an error retrieving the file.')
}
res.writeHead(200, { 'Content-Type': 'image/png' })
res.end(str, 'binary')
})
socket.resume()
})
})
Any help is appreciated, thanks!