forked from Risk-DAO/bad-debt-leaderboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3Client.js
78 lines (64 loc) · 1.56 KB
/
s3Client.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
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
68
69
70
71
72
73
74
75
76
77
78
const AWS = require('aws-sdk')
const s3 = new AWS.S3()
const BUCKET_NAME = process.env.BUCKET_NAME
const uploadJsonFile = (jsonString, fileName) => {
return new Promise((resolve, reject) => {
// Read content from the file
// Setting up S3 upload parameters
const params = {
Bucket: BUCKET_NAME,
Key: fileName, // File name you want to save as in S3
Body: jsonString,
ACL: 'private'
};
console.log(params)
// Uploading files to the bucket
s3.upload(params, function(err, data) {
if (err) {
reject(err)
return
}
console.log(`File uploaded successfully.`);
resolve(data)
});
})
}
const getJsonFile = (fileName) => {
return new Promise((resolve, reject) => {
// Read content from the file
// Setting up S3 parameters
const params = {
Bucket: BUCKET_NAME,
Key: fileName, // File name you want in S3
};
// Uploading files to the bucket
s3.getObject(params, function(err, data) {
if (err) {
reject(err)
return
}
resolve(data)
});
})
}
const listJsonFiles = () => {
return new Promise((resolve, reject) => {
// Setting up S3 parameters
const params = {
Bucket: BUCKET_NAME,
};
// Uploading files to the bucket
s3.listObjects(params, function(err, data) {
if (err) {
reject(err)
return
}
resolve(data)
});
})
}
module.exports = {
uploadJsonFile,
listJsonFiles,
getJsonFile
}