Reputation: 125
I am using Node to upload mp3 files to Amazon S3. When I upload it, the file size is 9.0 Bytes and when I go to the public url, the audio file doesnt play. This is what I have,
router.post('/i', async (req, res) => {
const fileName = 'Voice.mp3';
fs.readFile(fileName, (err, data) => {
if (err) throw err;
const params = {
Bucket: '',
Key: '',
Body: fileName,
ContentType: 'audio/mpeg',
};
s3.upload(params, function (s3Err, data) {
if (s3Err) throw s3Err;
console.log(`File uploaded successfully at ${data.Location}`);
});
});
});
I have a local file called Voice.mp3. It uses the correct file to upload because when I change the var fileName, it gives me an error.
The fileName shows in the S3 bucket but the size and the actual file doesn't match.
I set permissions to be accessible to public as well.
Upvotes: 0
Views: 1403
Reputation: 132912
The Body
parameter is set to fileName
, which is the name of the file, not the file contents, which I think is what you intended.
Change the code to say Body: data
and it will upload the actual file contents.
Upvotes: 2