-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy paths3Service.js
33 lines (27 loc) · 842 Bytes
/
s3Service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { S3 } = require("aws-sdk");
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const uuid = require("uuid").v4;
exports.s3Uploadv2 = async (files) => {
const s3 = new S3();
const params = files.map((file) => {
return {
Bucket: process.env.AWS_BUCKET_NAME,
Key: `uploads/${uuid()}-${file.originalname}`,
Body: file.buffer,
};
});
return await Promise.all(params.map((param) => s3.upload(param).promise()));
};
exports.s3Uploadv3 = async (files) => {
const s3client = new S3Client();
const params = files.map((file) => {
return {
Bucket: process.env.AWS_BUCKET_NAME,
Key: `uploads/${uuid()}-${file.originalname}`,
Body: file.buffer,
};
});
return await Promise.all(
params.map((param) => s3client.send(new PutObjectCommand(param)))
);
};