Lee SeJin

Connect AWS s3

...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 "author": "Lee SeJin", 17 "author": "Lee SeJin",
18 "license": "MIT", 18 "license": "MIT",
19 "dependencies": { 19 "dependencies": {
20 + "aws-sdk": "^2.922.0",
20 "axios": "^0.21.1", 21 "axios": "^0.21.1",
21 "connect-mongo": "^4.4.1", 22 "connect-mongo": "^4.4.1",
22 "dotenv": "^9.0.2", 23 "dotenv": "^9.0.2",
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
25 "mongoose": "^5.12.9", 26 "mongoose": "^5.12.9",
26 "morgan": "^1.10.0", 27 "morgan": "^1.10.0",
27 "multer": "^1.4.2", 28 "multer": "^1.4.2",
29 + "multer-s3": "^2.9.0",
28 "node-fetch": "^2.6.1", 30 "node-fetch": "^2.6.1",
29 "nodemon": "^2.0.7", 31 "nodemon": "^2.0.7",
30 "passport": "^0.4.1", 32 "passport": "^0.4.1",
......
...@@ -29,7 +29,7 @@ export const getUserDetail = async (req, res) => { ...@@ -29,7 +29,7 @@ export const getUserDetail = async (req, res) => {
29 const user = await User.findById(id); 29 const user = await User.findById(id);
30 const totalCon = await getContributions(user.githubName); 30 const totalCon = await getContributions(user.githubName);
31 res.render("userDetail", { 31 res.render("userDetail", {
32 - pagetTitle: "User Detail", 32 + pageTitle: "User Detail",
33 quote: quote.quote, 33 quote: quote.quote,
34 author: quote.author, 34 author: quote.author,
35 user, 35 user,
...@@ -67,7 +67,7 @@ export const postEditProfile = async (req, res) => { ...@@ -67,7 +67,7 @@ export const postEditProfile = async (req, res) => {
67 const updatedUser = await User.findByIdAndUpdate( 67 const updatedUser = await User.findByIdAndUpdate(
68 id, 68 id,
69 { 69 {
70 - avatarUrl: file ? file.path : req.session.passport.user.avatarUrl, 70 + avatarUrl: file ? file.location : req.session.passport.user.avatarUrl,
71 name, 71 name,
72 email, 72 email,
73 school, 73 school,
......
1 import multer from "multer"; 1 import multer from "multer";
2 +import multerS3 from "multer-s3";
3 +import aws from "aws-sdk";
4 +
5 +const s3 = new aws.S3({
6 + credentials: {
7 + accessKeyId: process.env.AWS_ID,
8 + secretAccessKey: process.env.AWS_SECRET
9 + }
10 +});
11 +
12 +const multerUploader = multerS3({
13 + s3: s3,
14 + bucket: "developer-profile-oss",
15 + acl: "public-read",
16 +})
2 17
3 export const localsMiddleware = (req,res,next) => { 18 export const localsMiddleware = (req,res,next) => {
4 res.locals.siteName = "Dev Profile"; 19 res.locals.siteName = "Dev Profile";
...@@ -27,5 +42,6 @@ export const uploadFiles = multer({ ...@@ -27,5 +42,6 @@ export const uploadFiles = multer({
27 dest:"uploads/", 42 dest:"uploads/",
28 limits: { 43 limits: {
29 fileSize: 3000000 44 fileSize: 3000000
30 - } 45 + },
46 + storage: multerUploader
31 }); 47 });
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,7 +3,7 @@ extends layouts/main ...@@ -3,7 +3,7 @@ extends layouts/main
3 block content 3 block content
4 .form-container 4 .form-container
5 form(action="/users/edit-profile", method="POST", enctype="multipart/form-data") 5 form(action="/users/edit-profile", method="POST", enctype="multipart/form-data")
6 - img(src=`/${loggedUser.avatarUrl}`) 6 + img(src=`${loggedUser.avatarUrl}`)
7 .fileUpload 7 .fileUpload
8 input(type="file", id="photo", name="photo", accept="image/*") 8 input(type="file", id="photo", name="photo", accept="image/*")
9 label(for="photo") Photo 9 label(for="photo") Photo
......
...@@ -9,7 +9,7 @@ block content ...@@ -9,7 +9,7 @@ block content
9 .pageLayout 9 .pageLayout
10 .user-profile 10 .user-profile
11 .user-profile__column 11 .user-profile__column
12 - img(src=`/${user.avatarUrl}`) 12 + img(src=`${user.avatarUrl}`)
13 .user-profile__link 13 .user-profile__link
14 a(href=user.githubUrl target="_blank") GitHub 14 a(href=user.githubUrl target="_blank") GitHub
15 i.fab.fa-github 15 i.fab.fa-github
......