my-roki / Rokitube

Youtube clone built using NodeJS, Express, Mogo and ES6
0 stars 0 forks source link

aws s3 upload error - TypeError: this.client.send is not a function #7

Open my-roki opened 2 years ago

my-roki commented 2 years ago

I created an aws s3 bucket and connected it to the multer middleware to create a file server in aws s3 instead local storage. However, after the build, the following error appears and the file is not uploaded normally.

here is my multer s3 code

import multerS3 from "multer-s3";
import aws from "aws-sdk";

const s3 = new aws.S3({
  credentials: {
    accessKeyId: process.env.AWS_ID,
    secretAccessKey: process.env.AWS_SECRET,
  },
});

const multerUploader = multerS3({
  s3: s3,
  bucket: "youtube-myroki",
});

export const uploadAvatar = multer({
  dest: "uploads/avatar/",
  limits: { fileSize: 3000000 },
  storage: multerUploader,
});

export const uploadVideo = multer({
  dest: "uploads/video/",
  limits: { fileSize: 536870912 },
  storage: multerUploader,
});

and then here is error.

TypeError: this.client.send is not a function
    at Upload.__uploadUsingPut (D:\Dev_study\youtube_clone\node_modules\@aws-sdk\lib-storage\dist-cjs\Upload.js:47:25)
    at Upload.__doConcurrentUpload (D:\Dev_study\youtube_clone\node_modules\@aws-sdk\lib-storage\dist-cjs\Upload.js:91:39)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at Upload.__doMultipartUpload (D:\Dev_study\youtube_clone\node_modules\@aws-sdk\lib-storage\dist-cjs\Upload.js:141:9)
    at Upload.done (D:\Dev_study\youtube_clone\node_modules\@aws-sdk\lib-storage\dist-cjs\Upload.js:37:16)
my-roki commented 2 years ago

Someone told me that this error is caused by the version of multer, aws-sdk, multer-s3. So I have to downgrade that three npm packages below

"aws-sdk": "^2.895.0",
"multer": "^1.4.2",
"multer-s3": "^2.9.0",
npm i aws-sdk@2.895.0
npm i multer@1.4.2
npm i multer-s3@2.9.0

solution: https://github.com/anacronw/multer-s3/issues/169

sherux commented 2 years ago

amazing solution and thanks for solution