Flare-k

[Add] AWS Service

...@@ -153,7 +153,7 @@ export const postEditProfile = async (req, res) => { ...@@ -153,7 +153,7 @@ export const postEditProfile = async (req, res) => {
153 await User.findByIdAndUpdate(req.user.id, { 153 await User.findByIdAndUpdate(req.user.id, {
154 name, 154 name,
155 email, 155 email,
156 - avatarUrl: file ? file.path : req.user.avatarUrl, 156 + avatarUrl: file ? file.location : req.user.avatarUrl, // S3 적용때메 file.path -> file.location 변경(06/24)
157 }); 157 });
158 res.redirect(routes.me); 158 res.redirect(routes.me);
159 } catch (error) { 159 } catch (error) {
......
...@@ -40,11 +40,11 @@ export const postUpload = async (req, res) => { ...@@ -40,11 +40,11 @@ export const postUpload = async (req, res) => {
40 // 이는 pug와 db.js를 확인해야하는 듯 하다. 40 // 이는 pug와 db.js를 확인해야하는 듯 하다.
41 const { 41 const {
42 body: { title, description }, 42 body: { title, description },
43 - file: { path }, 43 + file: { location }, // path로 할때는 로컬의 경로. S3는 location
44 } = req; // file에 path라는 요소가 있다. 44 } = req; // file에 path라는 요소가 있다.
45 45
46 const newVideo = await Video.create({ 46 const newVideo = await Video.create({
47 - fileUrl: path, 47 + fileUrl: location,
48 title, 48 title,
49 description, 49 description,
50 creator: req.user.id, 50 creator: req.user.id,
......
1 +import dotenv from "dotenv";
1 import multer from "multer"; 2 import multer from "multer";
3 +import multerS3 from "multer-s3";
4 +import aws from "aws-sdk";
2 import routes from "./routes"; 5 import routes from "./routes";
3 6
4 -const multerVideo = multer({ dest: "uploads/videos/" }); 7 +dotenv.config();
5 -const multerAvatar = multer({ dest: "uploads/avatars/" }); 8 +
9 +const s3 = new aws.S3({
10 + accessKeyId: process.env.AWS_KEY,
11 + secretAccessKey: process.env.AWS_PRIVATEE_KEY,
12 + region: "ap-northeast-2",
13 +});
14 +
15 +// const multerVideo = multer({ dest: "uploads/videos/" });
16 +const multerVideo = multer({
17 + storage: multerS3({
18 + s3,
19 + acl: "public-read",
20 + bucket: "khutube/video",
21 + }),
22 +});
23 +// const multerAvatar = multer({ dest: "uploads/avatars/" });
24 +const multerAvatar = multer({
25 + storage: multerS3({
26 + s3,
27 + acl: "public-read",
28 + bucket: "khutube/avatars",
29 + }),
30 +});
6 31
7 export const localsMiddleware = (req, res, next) => { 32 export const localsMiddleware = (req, res, next) => {
8 res.locals.siteName = "my Youtube"; 33 res.locals.siteName = "my Youtube";
......
1 mixin videoPlayer(video={}) 1 mixin videoPlayer(video={})
2 .videoPlayer#jsVideoPlayer 2 .videoPlayer#jsVideoPlayer
3 - video(src=`/${video.src}`) 3 + video(src=video.src)
4 .videoPlayer__controls 4 .videoPlayer__controls
5 .videoPlayer__column 5 .videoPlayer__column
6 span#jsVolumeBtn 6 span#jsVolumeBtn
......