Cannot Get Error from getObject API to download/get an object(audio file) from S3
0
My call recordings of amazon connect are being stored on S3 in .wav file, i am looking to get and play those recordings in a third party application. For this i am using getObject API
& trying to get/download the .wav files by name but i am getting the Cannot Get Error
.
At the same time i do want to provide the path in key e.g. Connect/Lab/2022/04/08/abc.wav
, is it possible?
How to resolve it? here is my code:
require("dotenv").config();
const expres = require("express");
const app = expres();
app.listen(3001);
const aws = require("aws-sdk");
aws.config.update({
secretAccessKey: process.env.ACCESS_SECRET,
accessKeyId: process.env.ACCESS_KEY,
region: process.env.REGION
})
const BUCKET = process.env.BUCKET
const Key = '/connect/oblab2/CallRecordings/2022/04/08/'
const s3 = new aws.S3(secretAccessKey = process.env.ACCESS_SECRET, accessKeyId = process.env.ACCESS_KEY);
app.get("/download/filename", async(req, res)=>{
const filename = req.params.filename
let x = await s3.getObject({Bucket:BUCKET, Key:Key + filename}).promise();
res.send(x.Body);
})
1 Answers
1
Accepted Answer
Achieved it through:
require("dotenv").config();
const aws = require('aws-sdk');
const expres = require("express");
const app = expres();
app.listen(3001);
app.get('/getfilefromS3', async (req, res, next) => {
aws.config.update({
secretAccessKey: process.env.ACCESS_SECRET,
accessKeyId: process.env.ACCESS_KEY,
region: process.env.REGION
})
const s3 = new aws.S3(secretAccessKey = process.env.ACCESS_SECRET, accessKeyId = process.env.ACCESS_KEY);
var params = { Bucket: process.env.BUCKET, Key: "connect/oblab2/CallRecordings/2022/04/08/" + req.query.filename };
s3.getObject(params, function (err, data) {
if (err) {
res.status(200);
res.end('Error Fetching File');
}
else {
res.attachment(params.Key); // Set Filename
res.type(data.ContentType); // Set FileType
res.send(data.Body); // Send File Buffer
}
});
})```
And than hitting endpoint:
http://localhost:3001/getfilefromS3?filename=filename.wav
answered 2 months ago
Relevant questions
How to get the amazon connect Phone call audio streams(Recordings) from S3 to Local environment
asked 2 months agoCannot Get Error from getObject API to download/get an object(audio file) from S3
Accepted Answerasked 2 months agoGet Attributes from Amazon Connect to Amazon Lex
asked 3 years agoUpload to S3 from Lambda doesn't create file in bucket, no error
asked a year agoHow to map call duration in call recordings of amazon connect?
Accepted Answerasked 23 days agoHow to get Call Status(Connected, Busy, No answered & Ringing) from Amazon Connect Streams API?
asked a month agoWhat timestamp is being used by Amazon Connect for recordings filename? Initiation timestamp OR Disconnect timestamp?
asked a month agoCallRecording FileName in S3
asked 3 years agoHow to make/access call recordings filenames
asked 2 months agoAre 'direct' derivative works of the recordings allowed?
asked 2 years ago