Home > Software design >  MulterS3 is giving this.client.send is not a function error
MulterS3 is giving this.client.send is not a function error

Time:06-04

Note: Getting below error in multer s3. This error is pointing NPM module and I really don't understand the issue with this module. I have used upload.single as well as upload.array method to check the working of this module. But not working.

Code:

const bodyParser = require('body-parser');
const cors = require('cors');

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

const http = require('http');
const app = express();

app.set('port', 3000);
app.use(
  bodyParser.json({
    limit: '50mb'
  })
);
app.use(
  bodyParser.urlencoded({
    limit: '50mb',
    extended: true
  })
);
app.use(cors());

aws.config.update({
  accessKeyId: '',
  secretAccessKey: ''
});

s3 = new aws.S3();

const upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: '',
    acl: 'public-read',
    contentType: multerS3.AUTO_CONTENT_TYPE,
    metadata: function (req, file, cb) {
      cb(null, {
        fieldName: file.fieldname
      });
    },
    key: function (req, file, cb) {
      let extArray = file.mimetype.split('/');
      let ext = extArray[extArray.length - 1];

      console.log(`ext ->> `, ext, ` file.fieldname ->> `, file.fieldname);

      cb(null, "test/"   Date.now().toString()   '.'   ext);
    },
    /* limits: {
      fileSize: 1024 * 1024 * 10
    } */
  })
});

(() => {
  server = http.createServer(app).listen(app.get('port'), () => {
    console.debug(`Server started ->> `);
    app.get('/test', (req, res) => {Mul
      res.send('Hello');
    });

    app.post('/media', upload.single('media'), (req, res) => {
      console.log(`req.files ->> `, req.file);
      res.send('Thanks for you waiting time');
    });
  });
})();

Error:

ext ->>  jpeg  file.fieldname ->>  media
TypeError: this.client.send is not a function
    at Upload.__uploadUsingPut (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:52:25)
    at Upload.__doConcurrentUpload (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:99:39)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Looking solution with multer-s3. Thank you in advance.

CodePudding user response:

Have you checked this issues ? https://github.com/anacronw/multer-s3/issues/169

please check your aws-sdk, multer-s3 version is compatible

CodePudding user response:

I had this same issue. Downgrading Multer.s3 to 2x version solve the problem!

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

  • Related