如何使用Node JS将.mp4视频上传到S3存储桶

时间:2018-11-02 19:13:15

标签: node.js amazon-web-services amazon-s3 aws-sdk-nodejs

下面是Rest API,用于将视频上传到S3,当播放器抛出无效文件格式时,无法通过下载来播放视频。

app.post('/ insert-video',async(req,res)=> {

const {
    data,
    name: fileName,
    size: fileSize,
    type: fileType
} = req.body

// ASW code start
const base64data = new Buffer(data, 'binary');

let params = {
    Bucket: "uploadvidoe",
    Key: fileName,
    ContentType: fileType,
    Body: base64data
};
try {
    let uploadPromise = await new AWS.S3().putObject(params).promise();
    console.log("Successfully uploaded data to bucket");
} catch (e) {
    console.log("Error uploading data: ", e);
}

});

0 个答案:

没有答案