Skip to content

Commit

Permalink
[#44] Feat: multer 설치 및 세팅 + sql 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
meoraeng committed Oct 11, 2022
1 parent 1a5f2a4 commit 541a52b
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ dist
.tern-port

# JSDoc output files
/backend/out
/backend/out

# Uploaded image files
/backend/public/images
2 changes: 2 additions & 0 deletions backend/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ create table User (userKey INT AUTO_INCREMENT PRIMARY KEY,
userName VARCHAR(20) UNIQUE KEY NOT NULL,
id VARCHAR(20) UNIQUE KEY NOT NULL,
passwd VARCHAR(64) NOT NULL,
imgUrl VARCHAR(200),
classKey INT NOT NULL,
FOREIGN KEY(classKey) REFERENCES Class(classKey));

Expand All @@ -18,6 +19,7 @@ create table Post (postKey INT AUTO_INCREMENT PRIMARY KEY,
postTime DATETIME DEFAULT CURRENT_TIMESTAMP,
title TEXT NOT NULL,
body TEXT NOT NULL,
imgUrl VARCHAR(200),
categoryKey INT NOT NULL,
careerPostKey INT,
FOREIGN KEY(categoryKey) REFERENCES Category(categoryKey),
Expand Down
3 changes: 2 additions & 1 deletion backend/src/loaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import expressLoader from "./express";
import mariadb from "./mariadb";
import Logger from "./logger";
import passport from "./passport";
import multer from "./multer";

export default async function (app) {
try {
Expand All @@ -13,7 +14,7 @@ export default async function (app) {


passport(app);

multer(app);
expressLoader(app);
Logger.info("🚅Express loaded");

Expand Down
18 changes: 18 additions & 0 deletions backend/src/loaders/multer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import multer from "multer";
import dotenv from "dotenv";

dotenv.config();

export default function (app) {
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '../../public/images');
},
filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
cb(null, file.fieldname + '-' + uniqueSuffix)
}
})

const upload = multer({ storage: storage });
}
Loading

0 comments on commit 541a52b

Please sign in to comment.