下面是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);
}
});