Super Kawaii Cute Cat Kaoani
본문 바로가기
⚡트러블 슈팅

[트러블 슈팅] AWS SDK와 Multer-S3 호환성 문제 발생

by wonee1 2025. 3. 3.
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