multer-s3 , aws-sdk버전 확인하기
npm i multer
npm i multer-s3@2.10.0
const multer = require("multer");
const multerS3 = require("multer-s3");
const AWS = require("aws-sdk");
const path = require("path");
require("dotenv").config();
AWS.config.update({
accessKeyId: <S3_ACCESS_KEY_ID>, // .env 맹신하지 말자
secretAccessKey: <S3_ACCESS_SECRET_KEY>, // .env 맹신하지 말자
region: "ap-northeast-2",
});
console.log(process.env.S3_ACCESS_KEY_ID);
const upload = multer({
storage: multerS3({
s3: new AWS.S3(),
bucket: <S3_BUCKET_NAME>,
acl: "public-read",
contentType: multerS3.AUTO_CONTENT_TYPE,
key(req, file, cb) {
cb(null, `${Date.now()}_${path.basename(file.originalname)}`); // original 폴더안에다 파일을 저장
},
}),
});
module.exports = upload;
const upload = require("../modules/multer");
...
router.post("/image", upload.single("img"), cardpostsController.imagepost);