728x90
๐จ ๋ฐ์ํ ๋ฌธ์ ์ ์ํฉ
Unhandled Error: TypeError: this.client.send is not a function
at _Upload.__uploadUsingPut
๐ค ๋ฌธ์ ์ ์์ธ ํ์ ํ๊ธฐ
์ด ์ค๋ฅ๋ AWS SDK v3๋ฅผ ์ฌ์ฉํ ๋ ๋ฐ์ํ๋ ๋ฌธ์
aws sdk๋ฅผ ์ฌ์ฉํ ๋ multer์ ํธํ์ฑ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด ์๊ธฐ๋ ๋ฌธ์ ๋ผ๊ณ ํ๋ค
๐๐ปโ๏ธ ์๋ํด๋ณธ ๋ฐฉ๋ฒ
1๏ธโฃAWS SDK ๋ฒ์ ์ฒดํฌ
npm uninstall @aws-sdk/client-s3
npm install aws-sdk@2.1356.0
2๏ธโฃ multer & multer-s3 ๋ค์ด๊ทธ๋ ์ด๋
npm uninstall multer multer-s3
npm install multer@1.4.2 multer-s3@2.9.0
โ 3๏ธโฃ imageUploader.ts ์์
import AWS from "aws-sdk";
import multer from "multer";
import multerS3 from "multer-s3";
import { v4 as uuidv4 } from "uuid";
import dotenv from "dotenv";
dotenv.config();
// โ
AWS S3 ์ค์
const s3 = new AWS.S3({
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY,
});
// โ
Multer-S3 ์คํ ๋ฆฌ์ง ์ค์
export const imageUploader = multer({
storage: multerS3({
s3: s3, // S3 ๊ฐ์ฒด
bucket: process.env.AWS_S3_BUCKET_NAME as string, // S3 ๋ฒํท ์ด๋ฆ
contentType: multerS3.AUTO_CONTENT_TYPE, // Content-Type ์๋ ์ค์
key: (_, file, callback) => {
const uploadDirectory = "uploads"; // โ
S3 ๋ด ์
๋ก๋ ํด๋ ์ง์
const uuid = uuidv4(); // UUID ์์ฑ
callback(null, `${uploadDirectory}/${uuid}_${file.originalname}`);
},
}),
// โ
ํ์ผ ์ฉ๋ ์ ํ (์ต๋ 5MB)
limits: { fileSize: 5 * 1024 * 1024 },
// โ
ํ์ผ ํํฐ (์ด๋ฏธ์ง ํ์ฅ์๋ง ํ์ฉ)
fileFilter: (_, file, callback) => {
const allowedExtensions = ["image/png", "image/jpg", "image/jpeg", "image/gif"];
if (!allowedExtensions.includes(file.mimetype)) {
return callback(new Error("ํ์ฉ๋์ง ์์ ํ์ฅ์์
๋๋ค."));
}
callback(null, true);
},
});
โ ๊ฒฐ๋ก
ํธํ์ฑ ๋ฌธ์ ์กฐ์ฌํ์....
๐ก์ฐธ๊ณ ๋ธ๋ก๊ทธ
[error] S3 multer upload, this.client.send
[error] S3 multer upload, this.client.send
โ๏ธ ์ด๋ฐ ๋ถ๋ถ์์ ์๋ฌ๊ฐ ๋ฐ์ ํ ์ค์ ๋ชฐ๋๊ณ , ํด๊ฒฐ์ฑ ์ ๋นจ๋ฆฌ ์ฐพ์์ ๋คํ์ด์๋ค๊ณ ์๊ฐํ๋ค.
velog.io
728x90
'{Troubleshooting}' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํธ๋ฌ๋ธ์ํ ] TMAP 204 NO_CONTENT ์ค๋ฅ (0) | 2025.09.29 |
---|---|
[ํธ๋ฌ๋ธ์ํ ] Git merge conflict ์ฒ๋ฆฌ ๋ฐฉ๋ฒ (3) | 2025.07.28 |
[ํธ๋ฌ๋ธ ์ํ ] Prisma mode: "insensitive" ์ต์ ์ MySQL ๋ฏธ์ง์ ๋ฌธ์ (0) | 2025.03.03 |
[ํธ๋ฌ๋ธ ์ํ ] AWS s3 ์ด๋ฏธ์ง ๊นจ์ง๋ ํ์ (0) | 2025.03.03 |