]>
git.r.bdr.sh - rbdr/captura-backend-example/blob - src/index.js
bae1fc0e5818cb827e55a6647da5919f87182991
1 const { S3Client
, PutObjectCommand
} = require('@aws-sdk/client-s3');
3 module
.exports
.handler
= async (event
) => {
4 const data
= Buffer
.from(event
.body
, 'base64');
6 const contentType
= event
.headers
['Content-Type'] || event
.headers
['content-type'];
12 fileExtension
= 'mp4';
17 body: 'Invalid Content-Type. Expected image/gif or video/mp4.',
21 const filename
= `${Date.now().toString()}.${fileExtension}`;
23 const client
= new S3Client({});
24 const command
= new PutObjectCommand({
25 Bucket: process
.env
.S3_BUCKET
,
29 ContentType: contentType
33 await client
.send(command
);
37 body: JSON
.stringify({
38 url: `https://${process.env.DOMAIN_NAME}/${filename}`
46 body: JSON
.stringify({ message: 'Error uploading file.' }),