]>
git.r.bdr.sh - rbdr/captura-backend-example/blob - src/index.js
11e400bd6708e16eae291a045260b254d700b28e
1 const { S3Client
, PutObjectCommand
} = require('@aws-sdk/client-s3');
4 * @type {import('aws-lambda').APIGatewayProxyHandler}
6 module
.exports
.handler
= async (event
) => {
7 const data
= Buffer
.from(event
.body
, 'base64');
9 const contentType
= event
.headers
['Content-Type'] || event
.headers
['content-type'];
10 switch (contentType
) {
12 fileExtension
= 'gif';
15 fileExtension
= 'mp4';
20 body: 'Invalid Content-Type. Expected image/gif or video/mp4.',
24 const filename
= `${Date.now().toString()}.${fileExtension}`;
26 const client
= new S3Client({});
27 const command
= new PutObjectCommand({
28 Bucket: process
.env
.S3_BUCKET
,
32 ContentType: contentType
36 await client
.send(command
);
40 body: JSON
.stringify({
41 url: `https://${process.env.DOMAIN_NAME}/${filename}`
49 body: JSON
.stringify({ message: 'Error uploading file.' }),