I'm using the Node AWS-SDK to upload files to an existing S3 bucket. With the code below, the file eventually uploads but it seems to return no status code a couple of times. Also, when the file successfully uploads, the return statement does not execute.
Code
exports.create = function(req, res) {
var stream = fs.createReadStream(req.file.path);
var params = {
Bucket: 'aws bucket',
Key: req.file.filename,
Body: stream,
ContentLength: req.file.size,
ContentType: 'audio/mp3'
};
var s3upload = s3.upload(params, options).promise();
s3upload
.then(function(data) {
console.log(data);
return res.sendStatus(201);
})
.catch(function(err) {
return handleError(err);
});
}
Logs
POST /api/v0/episode/upload - - ms - -
POST /api/v0/episode/upload - - ms - -
{ Location: 'https://krazykidsradio.s3-us-west-2.amazonaws.com/Parlez-vous%2BFrancais.mp3',
Bucket: 'krazykidsradio',
Key: 'Parlez-vous+Francais.mp3',
ETag: '"f3ecd67cf9ce17a7792ba3adaee93638-11"' }