anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

var upload = this.s3.upload(params) TypeError: this.s3.upload is not a function #79

Closed simran-k closed 3 years ago

simran-k commented 7 years ago
aws.config.update({
    secretAccessKey: 'key',
    accessKeyId: 'secret',
});

var s3 = new aws.S3()

var upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'pdsfiles',
    metadata: function (req, file, cb) {
      cb(null, {fieldName: file.fieldname});
    },
    key: function (req, file, cb) {
      cb(null, Date.now().toString())
    }
  })
})

This is what the error looks like:

TypeError: this.s3.upload is not a function at S3Storage. (/home/simran/Downloads/NODE-BACKEND/node_modules/multer-s3/index.js:172:26) at /home/simran/Downloads/NODE-BACKEND/node_modules/multer-s3/index.js:58:10 at S3Storage.getContentType (/home/simran/Downloads/NODE-BACKEND/node_modules/multer-s3/index.js:8:5) at /home/simran/Downloads/NODE-BACKEND/node_modules/multer-s3/index.js:55:13 at end (/home/simran/Downloads/NODE-BACKEND/node_modules/run-parallel/index.js:16:15) at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

Call:

router.put('/updatePatternGrading/:pattern_number', upload.any(), function(req, res){
     console.log("request obj after manipulation", req.files);
     callAPI(req, res, fn.bind(apiObj, 'updatePatternGrading'));
 })

Why do I get this ?

simran-k commented 7 years ago

Can I have a response on this, please? It feels impossible to use this package :'(

LinusU commented 7 years ago

Hmm 🤔

It might be that you need to have new before multerS3, i.e. storage: new multerS3({.

We should probably throw an error to make that more clear though...

LinusU commented 3 years ago

Happy to accept PR that throws error if new is omitted