-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra.js
52 lines (47 loc) · 1.49 KB
/
extra.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
if (!file) {
const error = new createError("Please add a content to upload");
error.httpStatusCode = 400;
return next(error);
}
else
{
const child = fork("video.js");
// Send message to child process
child.send({ name: file.filename });
// Listen for message from child process
child.on("message", (message) => {
const { statusCode, text } = message;
if(statusCode==200)
{
// thumbnail uploads/files[1].filename
// content temp/files[0].filename
// Store Img temp/files[2].filename
const key="posts/"+req.files[0].filename
const params = {
ACL: "public-read-write",
Body:fs.createReadStream("temp/"+req.files[0].filename),
Bucket: process.env.AWS_BUCKET_NAME,
Key: key,
};
s3.putObject(
(params,
(err, data) => {
if (err) {
console.log(err)
}
res.status(200).send(data);
})
);
}
else
{
res.status(statusCode).send(text);
}
});
}
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECREAT_KEY,
region: process.env.AWS_REGION,
Bucket: process.env.AWS_BUCKET_NAME,
})