anacronw / multer-s3

multer storage engine for amazon s3
MIT License
662 stars 193 forks source link

this.client.send is not a function #169

Closed victorbianconi closed 2 years ago

victorbianconi commented 2 years ago

I've been trying to get around this error for a while but it keeps popping up, and S3 keeps billing me the requests even if no files are being uploaded.

This is my code:

require("dotenv").config();
const uniqid = require("uniqid");
const bucketName = process.env.AWS_POSTS_BUCKET_NAME;
const region = process.env.AWS_POSTS_BUCKET_REGION;
const accessKeyId = process.env.AWS_S3_UPLOADS_ACCESS_KEY;
const secretAccessKey = process.env.AWS_S3_UPLOADS_SECRET_KEY;

const aws = require("aws-sdk");
const multer = require("multer");
const multerS3 = require("multer-s3");

const s3 = new aws.S3({
  region,
  accessKeyId,
  secretAccessKey,
});

const path = uniqid();

exports.upload = multer({
  storage: multerS3({
    s3,
    bucket: bucketName,
    metadata: function (req, file, cb) {
      cb(null, { fieldName: path });
    },
    key: function (req, file, cb) {
      cb(null, path + "." + file.originalname.split(".")[1]);
    },
  }),
});

If I log the file it's being logged, but I get this.client.send is not a function every time and I don't see any new files on the bucket, but I realized I'm still being billed for the requests...

khalidahmed1101 commented 2 years ago

Same issue happening with me, Any solution please, thanks

LinusU commented 2 years ago

Which version of Multer S3 are you using? and which version of the AWS SDK?

victorbianconi commented 2 years ago

Multer S3: 3.00, AWS SDK: 2.1145.0

LinusU commented 2 years ago

Multer S3 2.x is compatible with AWS SDK 2.x, and Multer S3 3.x is compatible with AWS SDK 3.x.

Either upgrade AWS SDK, or downgrade Multer S3.