1

How do I pipe the stream from my downloadWithBuffers function into the res of my sequence_stream API? I can get the stream to work when I run the downloadWithBuffers function directly in the file passing in the params with correct bucket and object key but I cant seem to figure out how to pipe the results to the APIs res

I appreciate any help

const S3 = require('aws-sdk').S3

const awsSettings = {
  region: 'us-east-2',
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}

const s3 = new S3(awsSettings)

function downloadWithBuffers(params) {
  s3.getObject(params)
    .on('httpData', function (chunk) {
      console.log(chunk)
    })
    .on('httpDone', function () {
      console.log('Done streaming file')
    })
    .send()
}

module.exports = { downloadWithBuffers }

Controller for route and API

const getStream = required('../functions/getStream')

// Serve stream for a specific image file.
exports.sequence_stream = (req, res) => {
  try {
    const params = { Bucket: '----', Key: '----' }
    getStream.downloadWithBuffers(params).pipe(res)
  } catch (error) {
    res.send(error)
  }
}
rf guy
  • 379
  • 10
  • 26

0 Answers0