-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3Service.js
More file actions
67 lines (53 loc) · 1.79 KB
/
s3Service.js
File metadata and controls
67 lines (53 loc) · 1.79 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const {S3 } = require("aws-sdk");
//const { param } = require("express/lib/request");
var {S3Client, PutObjectCommand} = require('@aws-sdk/client-s3');
const uuid = require("uuid").v4;
// s3 v2
exports.s3uploadv2 = async (files) =>{
const s3 = new S3();
// upload just one file
// const param = {
// Bucket: process.env.AWS_BUCKET_NAME,
// Key: `uploads/${uuid()}-${file.originalname}`,
// //Secret_key: process.env.AWS_SECRET_ACCESS_KEY,
// Body: file.buffer
// }
//console.log('clé : ', param);
//return await s3.upload(param).promise();
// upload more than one files
const params = files.map(file =>{
return {
Bucket: process.env.AWS_BUCKET_NAME,
Key: `uploads/${uuid()}-${file.originalname}`,
//Secret_key: process.env.AWS_SECRET_ACCESS_KEY,
Body: file.buffer
}
});
return await Promise.all(
params.map(param => s3.upload(param).promise())
);
};
// s3 v3
exports.s3uploadv3 = async (files) =>{
const s3client = new S3Client();
// upload one file on v3
// const param = {
// Bucket: process.env.AWS_BUCKET_NAME,
// Key: `uploads/${uuid()}-${file.originalname}`,
// //Secret_key: process.env.AWS_SECRET_ACCESS_KEY,
// Body: file.buffer
// };
// return s3client.send(new PutObjectCommand(param))
// upload many files on v3
const params = files.map(file =>{
return {
Bucket: process.env.AWS_BUCKET_NAME,
Key: `uploads/${uuid()}-${file.originalname}`,
//Secret_key: process.env.AWS_SECRET_ACCESS_KEY,
Body: file.buffer
}
});
return await Promise.all(
params.map(param => s3client.send(new PutObjectCommand(param)))
);
};