npm i multer-s3
npm i aws-sdk
middlewares.js
+
import multerS3 from "multer-s3";
import aws from "aws-sdk";
const s3 = new aws.S3({
accessKeyId: process.env.AWS_KEY,
secretAccessKey: process.env.AWS_PRIVATE_KEY,
region: "ap-northeast-2"
});
// AWS S3 STORAGE 설정으로 변경
// const multerVideo = multer({dest: "uploads/videos/"});
const multerVideo = multer({
storage: multerS3({
s3,
acl:"public-read",
bucket: "wetube8230/video"
})
});
videoController.js
...
export const postUpload = async (req,res) => {
const { body : { title, description, _id }, file : {location} } = req;
const { user } = req;
console.log(file)
try{
const newVideo = await Video.create({
fileUrl : path,
fileUrl : location,
title : title,
description : description,
creator: req.user.id
...