I'm attempting to render an MP3 file on the front-end and send it to AWS S3. I can upload a given file to AWS S3 easily enough, but not from the buffer, which is where the file is generated.
The textToSpeech call in the code sample below is coming from the IBM Watson Text-to-Speech API.
Here is an example code, the app is a Next.JS app that is calling S3 via an API:
module.exports = requireAuth(async (req, res) => {
textToSpeech
.synthesize(synthesizeParams)
.then(buffer => {
const s3Params = {
Bucket: 'waveforms/audioform',
Key: 'CONTENT.mp3',
Body: buffer,
ContentType: 'audio/mpeg',
ACL: 'public/read'
}
s3.upload(s3Params, function (s3Err, data) {
if (s3Err) throw s3Err
console.log(`File uploaded successfully at ${data.Location}`)
})
})
.catch(err => {
console.log('error:', err)
})
}
The error is Error: Unsupported body payload object, so it appears that the buffer is not being accessed correctly, but I'm not sure how to extract the relevant data.
How can I pass a file from the Node buffer to S3?