-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3operations.js
34 lines (26 loc) · 950 Bytes
/
s3operations.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
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const path = require('path');
const fs = require('fs');
const REGION = "us-east-1"; //e.g. "us-east-1"
exports.uploadFilePromise = function (bucketName, filePath) {
return new Promise((resolve, reject) => {
const uploadParams = { Bucket: bucketName };
const s3 = new S3Client({ region: REGION });
var fileStream = fs.createReadStream(filePath);
fileStream.on('error', function (err) {
console.log('File Error', err);
});
uploadParams.Body = fileStream;
var path = require('path');
uploadParams.Key = path.basename(filePath);
const run = async () => {
try {
data = await s3.send(new PutObjectCommand(uploadParams));
resolve('success');
} catch (err) {
reject(err);
}
};
run();
})
}