Lee SeJin

Connect AWS s3

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